diff --git a/lib/database/mocks/alerting-mock.js b/lib/database/mocks/alerting-mock.js new file mode 100644 index 0000000..6726f8d --- /dev/null +++ b/lib/database/mocks/alerting-mock.js @@ -0,0 +1,11 @@ +export const silencedMock = () => { + return [ + { + name: `failing`, + class: `failing.js`, + method: "FAKEMETHOD", + id: 0, + silencedUntil: new Date().toJSON(), + }, + ]; +}; diff --git a/lib/database/mocks/alerting.json b/lib/database/mocks/alerting.json deleted file mode 100644 index f98f5cc..0000000 --- a/lib/database/mocks/alerting.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "silenced": [ - { - "name": "Test1", - "class": "TestClass1", - "method": "TestMethod1", - "regions": ["us"], - "alerting": "MyUtcDate" - }, - { - "name": "Test2", - "class": null, - "method": "TestMethod1", - "regions": [], - "alerting": "MyUtcDate" - }, - { - "name": "*", - "class": "*", - "method": "TestMethod1", - "regions": [], - "alerting": "MyUtcDate" - }, - { - "name": "Test3", - "class": "TestClass3", - "method": "*", - "regions": ["us", "au"], - "alerting": "MyUtcDate" - } - ] -} diff --git a/lib/database/mocks/catalog-mock.js b/lib/database/mocks/catalog-mock.js new file mode 100644 index 0000000..4368946 --- /dev/null +++ b/lib/database/mocks/catalog-mock.js @@ -0,0 +1,153 @@ +export const testsMock = () => { + return [ + { + id: 0, + name: "single", + class: "single.js", + image: "node:latest", + isPipeline: false, + type: "api", + description: "This is a single test", + tags: ["cron_1hour", "reg_us", "env_ci", "proj_core", "skip_alt"], + path: "tests/assets/suite/single.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 1, + name: "failing", + class: "failing.js", + image: "node:latest", + isPipeline: false, + type: "ui", + description: "This is a failing test", + tags: ["cron_1hour", "reg_us", "env_ci", "proj_core"], + path: "tests/assets/suite/failing.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 2, + name: "primary", + class: "primary.js", + image: "node:latest", + isPipeline: true, + type: "api", + description: "This is a primary test", + tags: [ + "cron_1hour", + "reg_us", + "proj_core", + "skip_alt", + "pipeline_secondary1", + ], + path: "tests/assets/suite/primary.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 3, + name: "secondary1", + class: "secondary1.js", + image: "node:latest", + isPipeline: true, + type: "api", + description: "This is a secondary test", + tags: [ + "cron_1hour", + "reg_us", + "proj_core", + "compound_tertiary1", + "compound_tertiary2", + ], + path: "tests/assets/suite/secondary1.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 4, + name: "secondary2", + class: "secondary2.js", + image: "node:latest", + isPipeline: true, + type: "api", + description: "This is a secondary2 test", + tags: ["cron_1hour", "reg_us", "proj_core", "compound_tertiary3"], + path: "tests/assets/suite/secondary2.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 5, + name: "tertiary1", + class: "tertiary1.js", + image: "node:latest", + isPipeline: true, + type: "api", + description: "This is a third test", + tags: ["cron_1hour", "reg_us", "proj_core"], + path: "tests/assets/suite/tertiary1.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 6, + name: "tertiary2", + class: "tertiary2.js", + image: "node:latest", + isPipeline: true, + type: "api", + description: "This is a third2 test", + tags: ["cron_1hour", "reg_us", "proj_core"], + path: "tests/assets/suite/tertiary2.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 5, + name: "tertiary3", + class: "tertiary3.js", + image: "node:latest", + isPipeline: true, + type: "api", + description: "This is a third3 test", + tags: ["cron_1hour", "reg_us", "proj_core"], + path: "tests/assets/suite/tertiary3.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + { + id: 6, + name: "single-alt", + class: "single-alt.js", + image: "node:latest", + isPipeline: false, + type: "ui", + description: "This is an alternative test", + tags: ["cron_1hour", "reg_us", "env_ci", "proj_alt"], + path: "tests/assets/suite/single-alt.js", + created: Date.now(), + mergeRequest: "https://example.com", + }, + ]; +}; + +export const mappingsMock = () => { + return [ + [ + { name: "primary", delay: 0 }, + { name: "secondary1", delay: 1000 }, + { name: "tertiary1", delay: 0 }, + ], + [ + { name: "primary", delay: 0 }, + { name: "secondary1", delay: 1000 }, + { name: "tertiary2", delay: 8000 }, + ], + [ + { name: "primary", delay: 0 }, + { name: "secondary2", delay: 0 }, + { name: "tertiary3", delay: 3000 }, + ], + ]; +}; diff --git a/lib/database/mocks/catalog.json b/lib/database/mocks/catalog.json deleted file mode 100644 index bf89bf3..0000000 --- a/lib/database/mocks/catalog.json +++ /dev/null @@ -1,92 +0,0 @@ -{ - "tests": [ - { - "name": "Test 1", - "class": "Test Class 1", - "compound": false, - "type": "api" - }, - { - "name": "Test 2", - "class": "Test Class 2", - "compound": false, - "type": "ui" - }, - { - "name": "Test Primary", - "class": "Test Class Primary", - "compound": true, - "type": "api" - }, - { - "name": "Test Secondary", - "class": "Test Class Secondary", - "compound": true, - "type": "ui" - } - ], - "tests:full": [ - { - "name": "Test1", - "class": "TestClass1", - "compound": false, - "type": "api", - "markers": ["Service1"], - "ignored": false, - "comment": "This Comment Is Part Of Test 1", - "coverage": ["/api/test1", "/api/test2"], - "env": ["prod", "ci"], - "path": "tests/api/test1.js", - "regions": ["us", "ca"], - "origin": "Repo1", - "cron": "1hour" - }, - { - "name": "Test2", - "class": "TestClass2", - "compound": false, - "type": "ui", - "markers": ["Service2"], - "ignored": false, - "comment": "Comment belonging to Test2", - "coverage": ["Page1/FeatureA"], - "env": ["prod"], - "path": "tests/ui/test2.js", - "regions": [], - "origin": "Repo2", - "cron": "30min" - }, - { - "name": "TestPrimary", - "class": "TestClassPrimary", - "compound": true, - "type": "api", - "markers": [ - "ServiceComplex", - "compound_Repo2!TestClassSecondary#TestSecondary" - ], - "ignored": false, - "comment": "Comment belonging to Test Primary", - "coverage": ["/api/compound"], - "env": ["ci"], - "path": "tests/api/primary.js", - "regions": [], - "origin": "Repo1", - "cron": "2hour" - }, - { - "name": "TestSecondary", - "class": "TestClassSecondary", - "compound": true, - "type": "ui", - "markers": ["ServiceComplex"], - "ignored": false, - "coverage": ["PageComplex/FeatureA"], - "env": ["ci"], - "path": "tests/ui/secondary.js", - "regions": [], - "origin": "Repo2", - "cron": "2hour" - } - ] -} diff --git a/lib/database/mocks/results-mock.js b/lib/database/mocks/results-mock.js new file mode 100644 index 0000000..e51bdb1 --- /dev/null +++ b/lib/database/mocks/results-mock.js @@ -0,0 +1,30 @@ +export const failingMock = () => { + return [ + { + name: "failing", + class: "failing.js", + timestamp: new Date().toJSON(), + method: "FAKEMETHOD", + cron: "1hour", + type: "api", + dailyFails: 12, + screenshot: "https://picsum.photos/1920/1080", + recentResults: [1, 0, 0, 1, 0], + isPipeline: false, + failedMessage: `Some Test FailureMessage`, + }, + { + name: "secondary1", + class: "secondary1.js", + timestamp: new Date().toJSON(), + method: "FAKEMETHOD", + cron: "1hour", + type: "api", + dailyFails: 1, + screenshot: "https://picsum.photos/1920/1080", + recentResults: [1, 0, 0, 1, 0], + isPipeline: true, + failedMessage: `Some Test FailureMessage from Secondary1`, + }, + ]; +}; diff --git a/lib/database/mocks/results.json b/lib/database/mocks/results.json deleted file mode 100644 index c0ddf9c..0000000 --- a/lib/database/mocks/results.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "results": [ - { - "name": "Test1", - "method": "Test1Method", - "env": "prod", - "timestamp": "2022-05-10T16:35:27.220Z", - "retry": false, - "failed": true, - "failed_message": "Some failure message", - "screenshot": "https://example.com", - "weblog": "https://example.com" - }, - { - "name": "Test2", - "method": "Test2Method", - "env": "prod", - "timestamp": "2022-05-10T16:35:31.682Z", - "retry": false, - "failed": true, - "failed_message": "Some failure message 2", - "screenshot": "https://example.com", - "weblog": "https://example.com" - }, - { - "name": "Test1", - "method": null, - "env": "prod", - "timestamp": "2022-05-10T16:35:33.810Z", - "retry": false, - "failed": false, - "failed_message": null, - "screenshot": "https://example.com", - "weblog": "https://example.com" - }, - { - "name": "Test1", - "method": null, - "env": "ci", - "timestamp": "2022-05-10T16:35:33.810Z", - "retry": false, - "failed": false, - "failed_message": null, - "screenshot": "https://example.com", - "weblog": "https://example.com" - } - ] -} diff --git a/lib/database/queries/alerting.js b/lib/database/queries/alerting.js index 5f6a2fe..f4296f2 100644 --- a/lib/database/queries/alerting.js +++ b/lib/database/queries/alerting.js @@ -1,4 +1,5 @@ import pg from "../postgres.js"; +import { silencedMock } from "../mocks/alerting-mock.js"; // Imports import { insertQuery, @@ -9,18 +10,6 @@ import { const table = "silenced_tests"; const PG_DISABLED = process.env.POSTGRES_DISABLED; -const silencedMock = () => { - return [ - { - name: `failing`, - class: `failing.js`, - method: "FAKEMETHOD", - id: 0, - silencedUntil: new Date().toJSON(), - }, - ]; -}; - // Queries export const getSilencedTests = async () => { if (PG_DISABLED) return silencedMock(); diff --git a/lib/database/queries/catalog.js b/lib/database/queries/catalog.js index 0caf167..b712675 100644 --- a/lib/database/queries/catalog.js +++ b/lib/database/queries/catalog.js @@ -8,149 +8,9 @@ import { // Constants const table = "tests"; const PG_DISABLED = process.env.POSTGRES_DISABLED; +import { testsMock, mappingsMock } from "../mocks/catalog-mock.js"; // Queries -const testsMock = () => { - return [ - { - id: 0, - name: "single", - class: "single.js", - image: "node:latest", - isPipeline: false, - type: "api", - description: "This is a single test", - tags: ["cron_1hour", "reg_us", "env_ci", "proj_core", "skip_alt"], - path: "tests/assets/suite/single.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 1, - name: "failing", - class: "failing.js", - image: "node:latest", - isPipeline: false, - type: "ui", - description: "This is a failing test", - tags: ["cron_1hour", "reg_us", "env_ci", "proj_core"], - path: "tests/assets/suite/failing.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 2, - name: "primary", - class: "primary.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a primary test", - tags: [ - "cron_1hour", - "reg_us", - "proj_core", - "skip_alt", - "pipeline_secondary1", - ], - path: "tests/assets/suite/primary.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 3, - name: "secondary1", - class: "secondary1.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a secondary test", - tags: [ - "cron_1hour", - "reg_us", - "proj_core", - "compound_tertiary1", - "compound_tertiary2", - ], - path: "tests/assets/suite/secondary1.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 4, - name: "secondary2", - class: "secondary2.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a secondary2 test", - tags: ["cron_1hour", "reg_us", "proj_core", "compound_tertiary3"], - path: "tests/assets/suite/secondary2.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 5, - name: "tertiary1", - class: "tertiary1.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a third test", - tags: ["cron_1hour", "reg_us", "proj_core"], - path: "tests/assets/suite/tertiary1.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 6, - name: "tertiary2", - class: "tertiary2.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a third2 test", - tags: ["cron_1hour", "reg_us", "proj_core"], - path: "tests/assets/suite/tertiary2.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 5, - name: "tertiary3", - class: "tertiary3.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a third3 test", - tags: ["cron_1hour", "reg_us", "proj_core"], - path: "tests/assets/suite/tertiary3.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - ]; -}; - -const mappingsMock = () => { - return [ - [ - { name: "primary", delay: 0 }, - { name: "secondary1", delay: 1000 }, - { name: "tertiary1", delay: 0 }, - ], - [ - { name: "primary", delay: 0 }, - { name: "secondary1", delay: 1000 }, - { name: "tertiary2", delay: 8000 }, - ], - [ - { name: "primary", delay: 0 }, - { name: "secondary2", delay: 0 }, - { name: "tertiary3", delay: 3000 }, - ], - ]; -}; - export const getTests = async () => { if (PG_DISABLED) return testsMock(); const query = `SELECT * from ${table}`; @@ -162,3 +22,9 @@ export const getPipelineMappings = async () => { const query = `SELECT * from ${table}`; return pg.query(query); }; + +export const getProjects = async () => { + if (PG_DISABLED) { + const tests = testsMock(); + } +}; diff --git a/lib/database/queries/results.js b/lib/database/queries/results.js index 1a3d47b..bd601b9 100644 --- a/lib/database/queries/results.js +++ b/lib/database/queries/results.js @@ -1,4 +1,5 @@ import pg from "../postgres.js"; +import { failingMock } from "../mocks/results-mock.js"; // Imports import { insertQuery, @@ -10,36 +11,6 @@ import { const table = "test_results"; const PG_DISABLED = process.env.POSTGRES_DISABLED; -const failingMock = () => { - return [ - { - name: "failing", - class: "failing.js", - timestamp: new Date().toJSON(), - method: "FAKEMETHOD", - cron: "1hour", - type: "api", - dailyFails: 12, - screenshot: "https://picsum.photos/1920/1080", - recentResults: [1, 0, 0, 1, 0], - isPipeline: false, - failedMessage: `Some Test FailureMessage`, - }, - { - name: "secondary1", - class: "secondary1.js", - timestamp: new Date().toJSON(), - method: "FAKEMETHOD", - cron: "1hour", - type: "api", - dailyFails: 1, - screenshot: "https://picsum.photos/1920/1080", - recentResults: [1, 0, 0, 1, 0], - isPipeline: true, - failedMessage: `Some Test FailureMessage from Secondary1`, - }, - ]; -}; // Queries export const insertTestResult = (testResult) => { const { diff --git a/src/util/queries.js b/src/util/queries.js index 1a72fb1..79db507 100644 --- a/src/util/queries.js +++ b/src/util/queries.js @@ -1,8 +1,11 @@ import { useQuery } from "@tanstack/react-query"; +import { silencedMock } from "@qltr/mocks/alerting-mock.js"; +import { failingMock } from "@qltr/mocks/results-mock.js"; +import { testsMock, mappingsMock } from "@qltr/mocks/catalog-mock.js"; const QUALITEER_URL = "https://qualiteer.elijahparker3.repl.co/api"; -const useMock = false; +const useMock = true; const asMock = (data) => ({ data }); @@ -11,188 +14,20 @@ const fetchApi = (subPath) => async () => export const useCatalogTests = () => useMock - ? asMock([ - { - id: 0, - name: "single", - class: "single.js", - image: "node:latest", - isPipeline: false, - type: "api", - description: "This is a single test", - tags: ["cron_1hour", "reg_us", "env_ci", "proj_core", "skip_alt"], - path: "tests/assets/suite/single.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 1, - name: "failing", - class: "failing.js", - image: "node:latest", - isPipeline: false, - type: "ui", - description: "This is a failing test", - tags: ["cron_1hour", "reg_us", "env_ci", "proj_core"], - path: "tests/assets/suite/failing.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 2, - name: "primary", - class: "primary.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a primary test", - tags: [ - "cron_1hour", - "reg_us", - "proj_core", - "skip_alt", - "pipeline_secondary1", - ], - path: "tests/assets/suite/primary.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 3, - name: "secondary1", - class: "secondary1.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a secondary test", - tags: [ - "cron_1hour", - "reg_us", - "proj_core", - "compound_tertiary1", - "compound_tertiary2", - ], - path: "tests/assets/suite/secondary1.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 4, - name: "secondary2", - class: "secondary2.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a secondary2 test", - tags: ["cron_1hour", "reg_us", "proj_core", "compound_tertiary3"], - path: "tests/assets/suite/secondary2.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 5, - name: "tertiary1", - class: "tertiary1.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a third test", - tags: ["cron_1hour", "reg_us", "proj_core"], - path: "tests/assets/suite/tertiary1.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 6, - name: "tertiary2", - class: "tertiary2.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a third2 test", - tags: ["cron_1hour", "reg_us", "proj_core"], - path: "tests/assets/suite/tertiary2.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - { - id: 5, - name: "tertiary3", - class: "tertiary3.js", - image: "node:latest", - isPipeline: true, - type: "api", - description: "This is a third3 test", - tags: ["cron_1hour", "reg_us", "proj_core"], - path: "tests/assets/suite/tertiary3.js", - created: Date.now(), - mergeRequest: "https://example.com", - }, - ]) + ? asMock(testsMock()) : useQuery(["catalogTests"], fetchApi("/catalog/tests")); export const usePipelineMappings = () => useMock - ? asMock([ - [ - { name: "primary", delay: 0 }, - { name: "secondary1", delay: 1000 }, - { name: "tertiary1", delay: 0 }, - ], - [ - { name: "primary", delay: 0 }, - { name: "secondary1", delay: 1000 }, - { name: "tertiary2", delay: 8000 }, - ], - [ - { name: "primary", delay: 0 }, - { name: "secondary2", delay: 20000 }, - { name: "tertiary3", delay: 3000 }, - ], - ]) + ? asMock(mappingsMock()) : useQuery(["pipelineMappings"], fetchApi("/catalog/pipeline-mappings")); export const useSilencedAlerts = () => useMock - ? asMock([ - { - name: `failing`, - class: `failing.js`, - method: "FAKEMETHOD", - id: 0, - silencedUntil: new Date().toJSON(), - }, - ]) + ? asMock(silencedMock()) : useQuery(["silenced"], fetchApi("/alerting/silenced")); export const useCurrentlyFailing = () => useMock - ? asMock([ - { - name: "failing", - class: "failing.js", - timestamp: new Date().toJSON(), - method: "FAKEMETHOD", - cron: "1hour", - type: "api", - dailyFails: 12, - screenshot: "https://picsum.photos/1920/1080", - recentResults: [1, 0, 0, 1, 0], - isPipeline: false, - failedMessage: `Some Test FailureMessage`, - }, - { - name: "secondary1", - class: "secondary1.js", - timestamp: new Date().toJSON(), - method: "FAKEMETHOD", - cron: "1hour", - type: "api", - dailyFails: 1, - screenshot: "https://picsum.photos/1920/1080", - recentResults: [1, 0, 0, 1, 0], - isPipeline: true, - failedMessage: `Some Test FailureMessage from Secondary1`, - }, - ]) + ? asMock(failingMock()) : useQuery(["failing"], fetchApi("/results/failing")); diff --git a/tests/assets/suite/runner.js b/tests/assets/suite/runner.js index 481d9e1..03ff5da 100644 --- a/tests/assets/suite/runner.js +++ b/tests/assets/suite/runner.js @@ -8,6 +8,7 @@ import tertiary2 from "./tertiary2.js"; import tertiary3 from "./tertiary3.js"; import single from "./single.js"; +import singleAlt from "./single-alt.js"; import failing from "./failing.js"; // Constants @@ -46,6 +47,8 @@ const runTests = () => { return tertiary3(pipeline.testData); case "single": return single(); + case "single-alt": + return singleAlt(); case "failing": return failing(); default: diff --git a/tests/assets/suite/single-alt.js b/tests/assets/suite/single-alt.js new file mode 100644 index 0000000..639fba3 --- /dev/null +++ b/tests/assets/suite/single-alt.js @@ -0,0 +1,4 @@ +export default function singleAltTest() { + console.log("This came from a single test!"); + return { status: 0 }; +} diff --git a/vite.config.js b/vite.config.js index 17e8015..0351ecd 100644 --- a/vite.config.js +++ b/vite.config.js @@ -29,6 +29,7 @@ export default () => { "@qltr/jobs": path.resolve("./src/ctx/JobContext.jsx"), "@qltr/store": path.resolve("./src/ctx/StoreContext.jsx"), "@qltr/initiator": path.resolve("./lib/sockets/clients/Initiator.js"), + "@qltr/mocks": path.resolve("./lib/database/mocks/") }, }, });