diff --git a/__tests__/httpServer/apiV1.test.js b/__tests__/httpServer/apiV1.test.js index 98a5051..167a0b2 100644 --- a/__tests__/httpServer/apiV1.test.js +++ b/__tests__/httpServer/apiV1.test.js @@ -38,6 +38,7 @@ let addProject let getAllGithubOrganizationsByProjectsId let getAllChecks let getCheckById +let getAllChecklists beforeAll(async () => { // Initialize server asynchronously @@ -51,7 +52,8 @@ beforeAll(async () => { addProject, getAllGithubOrganizationsByProjectsId, getAllChecks, - getCheckById + getCheckById, + getAllChecklists } = initializeStore(knex)) }) @@ -398,8 +400,12 @@ describe('HTTP Server API V1', () => { const storedChecks = await getAllChecks() expect(response.status).toBe(200) - // @TODO: find a more elegant way to solve the issue with the date format - expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedChecks))) + const expected = storedChecks.map(c => ({ + ...c, + created_at: c.created_at.toISOString(), + updated_at: c.updated_at.toISOString() + })) + expect(response.body).toStrictEqual(expected) }) test.todo('should return 500 for internal server error') @@ -411,8 +417,12 @@ describe('HTTP Server API V1', () => { const storedCheck = await getCheckById(1) expect(response.status).toBe(200) - // @TODO: find a more elegant way to solve the issue with the date format - expect(response.body).toStrictEqual(JSON.parse(JSON.stringify(storedCheck))) + const expected = { + ...storedCheck, + created_at: storedCheck.created_at.toISOString(), + updated_at: storedCheck.updated_at.toISOString() + } + expect(response.body).toStrictEqual(expected) }) test('should return 400 for invalid check ID', async () => { @@ -433,4 +443,21 @@ describe('HTTP Server API V1', () => { test.todo('should return 500 for internal server error') }) + + describe('GET /api/v1/compliance-checklist', () => { + test('should return 200 and a list of checklists', async () => { + const response = await app.get('/api/v1/compliance-checklist') + const storedChecklists = await getAllChecklists() + + expect(response.status).toBe(200) + const expected = storedChecklists.map(c => ({ + ...c, + created_at: c.created_at.toISOString(), + updated_at: c.updated_at.toISOString() + })) + expect(response.body).toStrictEqual(expected) + }) + + test.todo('should return 500 for internal server error') + }) }) diff --git a/src/httpServer/routers/apiV1.js b/src/httpServer/routers/apiV1.js index e7cc0c8..3697772 100644 --- a/src/httpServer/routers/apiV1.js +++ b/src/httpServer/routers/apiV1.js @@ -27,7 +27,7 @@ const runWorkflow = ({ workflowName, knex, data } = {}) => new Promise((resolve, }) function createApiRouter (knex, express) { - const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId, getAllChecks, getCheckById } = initializeStore(knex) + const { addProject, getProjectByName, addGithubOrganization, getProjectById, getAllGithubOrganizationsByProjectsId, getAllChecks, getCheckById, getAllChecklists } = initializeStore(knex) const router = express.Router() @@ -146,6 +146,16 @@ function createApiRouter (knex, express) { } }) + router.get('/compliance-checklist', async (req, res) => { + try { + const checklists = await getAllChecklists() + res.json(checklists) + } catch (error) { + logger.error(error) + res.status(500).json({ errors: [{ message: 'Failed to retrieve Compliance Checklists' }] }) + } + }) + router.get('/workflow', (req, res) => { try { const { workflowsList } = getWorkflowsDetails() diff --git a/src/httpServer/swagger/api-v1.yml b/src/httpServer/swagger/api-v1.yml index 2c71e94..8fcbd69 100644 --- a/src/httpServer/swagger/api-v1.yml +++ b/src/httpServer/swagger/api-v1.yml @@ -69,7 +69,6 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - /api/v1/workflow/{workflowId}/run: post: summary: Execute a workflow @@ -325,9 +324,73 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' + /api/v1/compliance-checklist: + get: + summary: List all compliance checklists + description: Returns a list of all compliance checklists + operationId: listComplianceChecklists + tags: + - Compliance Checklists + responses: + '200': + description: A list of compliance checklists + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/ComplianceChecklist' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' components: schemas: + ComplianceChecklist: + type: object + additionalProperties: false + properties: + id: + type: integer + example: 1 + author: + type: string + example: "OpenJS Foundation" + title: + type: string + maxLength: 255 + example: "Security Compliance Guide v1.0 - Incubating" + description: + type: string + example: "This checklist is for projects that are in the incubating phase and have multiple maintainers." + code_name: + type: string + maxLength: 255 + example: "OpenJS-SCGv1.0-incubating" + url: + type: string + example: "https://openpathfinder.com/docs/checklists/OpenJS-SCGv1.0-incubating" + created_at: + type: string + format: date-time + example: "2025-02-21T18:53:00.485Z" + updated_at: + type: string + format: date-time + example: "2025-02-21T18:53:00.485Z" + required: + - id + - author + - title + - description + - code_name + - url + - created_at + - updated_at + ComplianceCheck: type: object additionalProperties: false @@ -400,7 +463,7 @@ components: - details_url - created_at - updated_at - + GithubOrganization: type: object additionalProperties: false @@ -618,6 +681,7 @@ components: - html_url - created_at - updated_at + Project: type: object additionalProperties: false @@ -741,6 +805,7 @@ components: - name - created_at - updated_at + ErrorObject: type: object properties: