Skip to content

Commit 609b84d

Browse files
committed
feat: add GET /api/v1/compliance-checklist endpoint
1 parent a925939 commit 609b84d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

__tests__/httpServer/apiV1.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let addProject
3838
let getAllGithubOrganizationsByProjectsId
3939
let getAllChecks
4040
let getCheckById
41+
let getAllChecklists
4142

4243
beforeAll(async () => {
4344
// Initialize server asynchronously
@@ -51,7 +52,8 @@ beforeAll(async () => {
5152
addProject,
5253
getAllGithubOrganizationsByProjectsId,
5354
getAllChecks,
54-
getCheckById
55+
getCheckById,
56+
getAllChecklists
5557
} = initializeStore(knex))
5658
})
5759

@@ -433,4 +435,17 @@ describe('HTTP Server API V1', () => {
433435

434436
test.todo('should return 500 for internal server error')
435437
})
438+
439+
describe('GET /api/v1/compliance-checklist', () => {
440+
test('should return 200 and a list of checklists', async () => {
441+
const response = await app.get('/api/v1/compliance-checklist')
442+
const storedChecklists = await getAllChecklists()
443+
444+
expect(response.status).toBe(200)
445+
// @TODO: find a more elegant way to solve the issue with the date format
446+
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecklists)))
447+
})
448+
449+
test.todo('should return 500 for internal server error')
450+
})
436451
})

src/httpServer/routers/apiV1.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const runWorkflow = ({ workflowName, knex, data } = {}) => new Promise((resolve,
2727
})
2828

2929
function createApiRouter (knex, express) {
30-
const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId, getAllChecks, getCheckById } = initializeStore(knex)
30+
const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId, getAllChecks, getCheckById, getAllChecklists } = initializeStore(knex)
3131

3232
const router = express.Router()
3333

@@ -146,6 +146,16 @@ function createApiRouter (knex, express) {
146146
}
147147
})
148148

149+
router.get('/compliance-checklist', async (req, res) => {
150+
try {
151+
const checklists = await getAllChecklists()
152+
res.json(checklists)
153+
} catch (error) {
154+
logger.error(error)
155+
res.status(500).json({ errors: [{ message: 'Failed to retrieve Compliance Checklists' }] })
156+
}
157+
})
158+
149159
router.get('/workflow', (req, res) => {
150160
try {
151161
const { workflowsList } = getWorkflowsDetails()

0 commit comments

Comments
 (0)