Skip to content

Commit ccd41d3

Browse files
committed
test: extend utils to support Alerts, Results and tasks operations
1 parent 44c41d1 commit ccd41d3

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

__utils__/index.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const resetDatabase = async (knex) => {
2+
await knex.raw('TRUNCATE TABLE compliance_checks_results RESTART IDENTITY CASCADE')
3+
await knex.raw('TRUNCATE TABLE compliance_checks_tasks RESTART IDENTITY CASCADE')
4+
await knex.raw('TRUNCATE TABLE compliance_checks_alerts RESTART IDENTITY CASCADE')
25
await knex.raw('TRUNCATE TABLE github_repositories RESTART IDENTITY CASCADE')
36
await knex.raw('TRUNCATE TABLE github_organizations RESTART IDENTITY CASCADE')
47
await knex.raw('TRUNCATE TABLE projects RESTART IDENTITY CASCADE')
@@ -23,7 +26,29 @@ const addGithubRepo = async (knex, data) => {
2326
return githubRepo
2427
}
2528

29+
const getAllResults = (knex) => knex('compliance_checks_results').select('*')
30+
const getAllTasks = (knex) => knex('compliance_checks_tasks').select('*')
31+
const getAllAlerts = (knex) => knex('compliance_checks_alerts').select('*')
32+
const addAlert = async (knex, alert) => {
33+
const [newAlert] = await knex('compliance_checks_alerts').insert(alert).returning('*')
34+
return newAlert
35+
}
36+
37+
const addTask = async (knex, task) => {
38+
const [newTask] = await knex('compliance_checks_tasks').insert(task).returning('*')
39+
return newTask
40+
}
41+
42+
const addResult = async (knex, result) => {
43+
const [newResult] = await knex('compliance_checks_results').insert(result).returning('*')
44+
return newResult
45+
}
46+
2647
const getAllComplianceChecks = (knex) => knex('compliance_checks').select('*')
48+
const getCheckByCodeName = async (knex, codeName) => {
49+
const check = await knex('compliance_checks').where({ code_name: codeName }).first()
50+
return check
51+
}
2752

2853
module.exports = {
2954
getAllComplianceChecks,
@@ -33,5 +58,12 @@ module.exports = {
3358
addProject,
3459
addGithubOrg,
3560
getAllGithubRepos,
36-
addGithubRepo
61+
addGithubRepo,
62+
getAllResults,
63+
getAllTasks,
64+
getAllAlerts,
65+
addAlert,
66+
addTask,
67+
addResult,
68+
getCheckByCodeName
3769
}

0 commit comments

Comments
 (0)