qualiteer/lib/database/queries/catalog.js

153 lines
3.8 KiB
JavaScript
Raw Normal View History

2022-05-08 01:36:22 +00:00
import pg from "../postgres.js";
// Imports
import {
insertQuery,
selectWhereAnyQuery,
updateWhereAnyQuery,
} from "../pg-query.js";
// Constants
const table = "tests";
2022-08-06 21:21:41 +00:00
const PG_DISABLED = process.env.POSTGRES_DISABLED;
2022-05-08 01:36:22 +00:00
// Queries
2022-08-06 21:21:41 +00:00
const testsMock = () => {
return [
{
id: 0,
name: "single",
class: "single.js",
image: "node:latest",
2022-08-10 12:39:09 +00:00
isPipeline: false,
2022-08-06 21:21:41 +00:00
type: "api",
description: "This is a single test",
2022-08-09 04:29:10 +00:00
tags: ["cron_1hour", "reg_us", "env_ci", "proj_core", "skip_alt"],
2022-08-06 21:21:41 +00:00
path: "tests/assets/suite/single.js",
created: Date.now(),
2022-08-09 04:29:10 +00:00
mergeRequest: "https://example.com",
2022-08-06 21:21:41 +00:00
},
2022-08-09 04:29:10 +00:00
{
2022-08-06 21:21:41 +00:00
id: 1,
name: "failing",
class: "failing.js",
image: "node:latest",
2022-08-10 12:39:09 +00:00
isPipeline: false,
2022-08-06 21:21:41 +00:00
type: "ui",
description: "This is a failing test",
2022-08-09 04:29:10 +00:00
tags: ["cron_1hour", "reg_us", "env_ci", "proj_core"],
2022-08-06 21:21:41 +00:00
path: "tests/assets/suite/failing.js",
created: Date.now(),
2022-08-09 04:29:10 +00:00
mergeRequest: "https://example.com",
2022-08-06 21:21:41 +00:00
},
2022-08-09 04:29:10 +00:00
{
2022-08-06 21:21:41 +00:00
id: 2,
name: "primary",
class: "primary.js",
image: "node:latest",
2022-08-10 12:39:09 +00:00
isPipeline: true,
2022-08-06 21:21:41 +00:00
type: "api",
description: "This is a primary test",
2022-08-09 04:29:10 +00:00
tags: [
"cron_1hour",
"reg_us",
"proj_core",
"skip_alt",
2022-08-10 12:39:09 +00:00
"pipeline_secondary1",
2022-08-09 04:29:10 +00:00
],
2022-08-06 21:21:41 +00:00
path: "tests/assets/suite/primary.js",
created: Date.now(),
2022-08-09 04:29:10 +00:00
mergeRequest: "https://example.com",
},
{
2022-08-06 21:21:41 +00:00
id: 3,
2022-08-10 12:39:09 +00:00
name: "secondary1",
class: "secondary1.js",
2022-08-06 21:21:41 +00:00
image: "node:latest",
2022-08-10 12:39:09 +00:00
isPipeline: true,
2022-08-06 21:21:41 +00:00
type: "api",
description: "This is a secondary test",
2022-08-10 12:39:09 +00:00
tags: [
"cron_1hour",
"reg_us",
"proj_core",
"compound_tertiary1",
"compound_tertiary2",
],
path: "tests/assets/suite/secondary1.js",
2022-08-06 21:21:41 +00:00
created: Date.now(),
2022-08-09 04:29:10 +00:00
mergeRequest: "https://example.com",
2022-08-06 21:21:41 +00:00
},
2022-08-09 04:29:10 +00:00
{
2022-08-06 21:21:41 +00:00
id: 4,
2022-08-10 12:39:09 +00:00
name: "secondary2",
class: "secondary2.js",
2022-08-06 21:21:41 +00:00
image: "node:latest",
2022-08-10 12:39:09 +00:00
isPipeline: true,
2022-08-06 21:21:41 +00:00
type: "api",
2022-08-10 12:39:09 +00:00
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",
2022-08-09 04:29:10 +00:00
tags: ["cron_1hour", "reg_us", "proj_core"],
2022-08-10 12:39:09 +00:00
path: "tests/assets/suite/tertiary3.js",
2022-08-06 21:21:41 +00:00
created: Date.now(),
2022-08-09 04:29:10 +00:00
mergeRequest: "https://example.com",
2022-08-06 21:21:41 +00:00
},
];
};
const mappingsMock = () => {
return [
2022-08-09 04:29:10 +00:00
["primary", "secondary1", "tertiary1"],
["primary", "secondary1", "tertiary2"],
["primary", "secondary2", "tertiary3"],
];
};
2022-08-06 21:21:41 +00:00
export const getTests = async () => {
if (PG_DISABLED) return testsMock();
const query = `SELECT * from ${table}`;
return pg.query(query);
};
export const getPipelineMappings = async () => {
if (PG_DISABLED) return mappingsMock();
2022-05-08 01:36:22 +00:00
const query = `SELECT * from ${table}`;
return pg.query(query);
};