Skip to content

Commit 1a8cae3

Browse files
authored
Merge pull request #247 from OpenPathfinder/ulises/v1-checklist
2 parents eefe787 + 73e1175 commit 1a8cae3

File tree

3 files changed

+110
-8
lines changed

3 files changed

+110
-8
lines changed

__tests__/httpServer/apiV1.test.js

Lines changed: 32 additions & 5 deletions
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

@@ -398,8 +400,12 @@ describe('HTTP Server API V1', () => {
398400
const storedChecks = await getAllChecks()
399401

400402
expect(response.status).toBe(200)
401-
// @TODO: find a more elegant way to solve the issue with the date format
402-
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecks)))
403+
const expected = storedChecks.map(c => ({
404+
...c,
405+
created_at: c.created_at.toISOString(),
406+
updated_at: c.updated_at.toISOString()
407+
}))
408+
expect(response.body).toStrictEqual(expected)
403409
})
404410

405411
test.todo('should return 500 for internal server error')
@@ -411,8 +417,12 @@ describe('HTTP Server API V1', () => {
411417
const storedCheck = await getCheckById(1)
412418

413419
expect(response.status).toBe(200)
414-
// @TODO: find a more elegant way to solve the issue with the date format
415-
expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedCheck)))
420+
const expected = {
421+
...storedCheck,
422+
created_at: storedCheck.created_at.toISOString(),
423+
updated_at: storedCheck.updated_at.toISOString()
424+
}
425+
expect(response.body).toStrictEqual(expected)
416426
})
417427

418428
test('should return 400 for invalid check ID', async () => {
@@ -433,4 +443,21 @@ describe('HTTP Server API V1', () => {
433443

434444
test.todo('should return 500 for internal server error')
435445
})
446+
447+
describe('GET /api/v1/compliance-checklist', () => {
448+
test('should return 200 and a list of checklists', async () => {
449+
const response = await app.get('/api/v1/compliance-checklist')
450+
const storedChecklists = await getAllChecklists()
451+
452+
expect(response.status).toBe(200)
453+
const expected = storedChecklists.map(c => ({
454+
...c,
455+
created_at: c.created_at.toISOString(),
456+
updated_at: c.updated_at.toISOString()
457+
}))
458+
expect(response.body).toStrictEqual(expected)
459+
})
460+
461+
test.todo('should return 500 for internal server error')
462+
})
436463
})

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()

src/httpServer/swagger/api-v1.yml

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ paths:
6969
application/json:
7070
schema:
7171
$ref: '#/components/schemas/ErrorResponse'
72-
7372
/api/v1/workflow/{workflowId}/run:
7473
post:
7574
summary: Execute a workflow
@@ -325,9 +324,73 @@ paths:
325324
application/json:
326325
schema:
327326
$ref: '#/components/schemas/ErrorResponse'
327+
/api/v1/compliance-checklist:
328+
get:
329+
summary: List all compliance checklists
330+
description: Returns a list of all compliance checklists
331+
operationId: listComplianceChecklists
332+
tags:
333+
- Compliance Checklists
334+
responses:
335+
'200':
336+
description: A list of compliance checklists
337+
content:
338+
application/json:
339+
schema:
340+
type: array
341+
items:
342+
$ref: '#/components/schemas/ComplianceChecklist'
343+
'500':
344+
description: Internal server error
345+
content:
346+
application/json:
347+
schema:
348+
$ref: '#/components/schemas/ErrorResponse'
328349

329350
components:
330351
schemas:
352+
ComplianceChecklist:
353+
type: object
354+
additionalProperties: false
355+
properties:
356+
id:
357+
type: integer
358+
example: 1
359+
author:
360+
type: string
361+
example: "OpenJS Foundation"
362+
title:
363+
type: string
364+
maxLength: 255
365+
example: "Security Compliance Guide v1.0 - Incubating"
366+
description:
367+
type: string
368+
example: "This checklist is for projects that are in the incubating phase and have multiple maintainers."
369+
code_name:
370+
type: string
371+
maxLength: 255
372+
example: "OpenJS-SCGv1.0-incubating"
373+
url:
374+
type: string
375+
example: "https://openpathfinder.com/docs/checklists/OpenJS-SCGv1.0-incubating"
376+
created_at:
377+
type: string
378+
format: date-time
379+
example: "2025-02-21T18:53:00.485Z"
380+
updated_at:
381+
type: string
382+
format: date-time
383+
example: "2025-02-21T18:53:00.485Z"
384+
required:
385+
- id
386+
- author
387+
- title
388+
- description
389+
- code_name
390+
- url
391+
- created_at
392+
- updated_at
393+
331394
ComplianceCheck:
332395
type: object
333396
additionalProperties: false
@@ -400,7 +463,7 @@ components:
400463
- details_url
401464
- created_at
402465
- updated_at
403-
466+
404467
GithubOrganization:
405468
type: object
406469
additionalProperties: false
@@ -618,6 +681,7 @@ components:
618681
- html_url
619682
- created_at
620683
- updated_at
684+
621685
Project:
622686
type: object
623687
additionalProperties: false
@@ -741,6 +805,7 @@ components:
741805
- name
742806
- created_at
743807
- updated_at
808+
744809
ErrorObject:
745810
type: object
746811
properties:

0 commit comments

Comments
 (0)