Skip to content

Commit 1eabdd0

Browse files
committed
feat: add GET /api/v1/check endpoint
1 parent 3c6ea8d commit 1eabdd0

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
@@ -36,6 +36,7 @@ let knex
3636
let getAllProjects
3737
let addProject
3838
let getAllGithubOrganizationsByProjectsId
39+
let getAllChecks
3940

4041
beforeAll(async () => {
4142
// Initialize server asynchronously
@@ -47,7 +48,8 @@ beforeAll(async () => {
4748
({
4849
getAllProjects,
4950
addProject,
50-
getAllGithubOrganizationsByProjectsId
51+
getAllGithubOrganizationsByProjectsId,
52+
getAllChecks
5153
} = initializeStore(knex))
5254
})
5355

@@ -387,4 +389,17 @@ describe('HTTP Server API V1', () => {
387389

388390
test.todo('should return 500 for internal server error')
389391
})
392+
393+
describe('GET /api/v1/check', () => {
394+
test('should return 200 and a list of checks', async () => {
395+
const response = await app.get('/api/v1/check')
396+
const storedChecks = await getAllChecks()
397+
398+
expect(response.status).toBe(200)
399+
// @TODO: find a more elegant way to solve the issue with the date format
400+
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecks)))
401+
})
402+
403+
test.todo('should return 500 for internal server error')
404+
})
390405
})

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 } = initializeStore(knex)
30+
const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId, getAllChecks } = initializeStore(knex)
3131

3232
const router = express.Router()
3333

@@ -121,6 +121,16 @@ function createApiRouter (knex, express) {
121121
}
122122
})
123123

124+
router.get('/check', async (req, res) => {
125+
try {
126+
const checks = await getAllChecks()
127+
res.json(checks)
128+
} catch (error) {
129+
logger.error(error)
130+
res.status(500).json({ errors: [{ message: 'Failed to retrieve checks' }] })
131+
}
132+
})
133+
124134
router.get('/workflow', (req, res) => {
125135
try {
126136
const { workflowsList } = getWorkflowsDetails()

0 commit comments

Comments
 (0)