Skip to content

Commit

Permalink
test: extend utils to support Alerts, Results and tasks operations
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Dec 7, 2024
1 parent 44c41d1 commit ccd41d3
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion __utils__/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const resetDatabase = async (knex) => {
await knex.raw('TRUNCATE TABLE compliance_checks_results RESTART IDENTITY CASCADE')
await knex.raw('TRUNCATE TABLE compliance_checks_tasks RESTART IDENTITY CASCADE')
await knex.raw('TRUNCATE TABLE compliance_checks_alerts RESTART IDENTITY CASCADE')
await knex.raw('TRUNCATE TABLE github_repositories RESTART IDENTITY CASCADE')
await knex.raw('TRUNCATE TABLE github_organizations RESTART IDENTITY CASCADE')
await knex.raw('TRUNCATE TABLE projects RESTART IDENTITY CASCADE')
Expand All @@ -23,7 +26,29 @@ const addGithubRepo = async (knex, data) => {
return githubRepo
}

const getAllResults = (knex) => knex('compliance_checks_results').select('*')
const getAllTasks = (knex) => knex('compliance_checks_tasks').select('*')
const getAllAlerts = (knex) => knex('compliance_checks_alerts').select('*')
const addAlert = async (knex, alert) => {
const [newAlert] = await knex('compliance_checks_alerts').insert(alert).returning('*')
return newAlert
}

const addTask = async (knex, task) => {
const [newTask] = await knex('compliance_checks_tasks').insert(task).returning('*')
return newTask
}

const addResult = async (knex, result) => {
const [newResult] = await knex('compliance_checks_results').insert(result).returning('*')
return newResult
}

const getAllComplianceChecks = (knex) => knex('compliance_checks').select('*')
const getCheckByCodeName = async (knex, codeName) => {
const check = await knex('compliance_checks').where({ code_name: codeName }).first()
return check
}

module.exports = {
getAllComplianceChecks,
Expand All @@ -33,5 +58,12 @@ module.exports = {
addProject,
addGithubOrg,
getAllGithubRepos,
addGithubRepo
addGithubRepo,
getAllResults,
getAllTasks,
getAllAlerts,
addAlert,
addTask,
addResult,
getCheckByCodeName
}

0 comments on commit ccd41d3

Please sign in to comment.