Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions __tests__/httpServer/apiV1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let addProject
let getAllGithubOrganizationsByProjectsId
let getAllChecks
let getCheckById
let getAllChecklists

beforeAll(async () => {
// Initialize server asynchronously
Expand All @@ -51,7 +52,8 @@ beforeAll(async () => {
addProject,
getAllGithubOrganizationsByProjectsId,
getAllChecks,
getCheckById
getCheckById,
getAllChecklists
} = initializeStore(knex))
})

Expand Down Expand Up @@ -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')
Expand All @@ -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 () => {
Expand All @@ -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')
})
})
12 changes: 11 additions & 1 deletion src/httpServer/routers/apiV1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
69 changes: 67 additions & 2 deletions src/httpServer/swagger/api-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

/api/v1/workflow/{workflowId}/run:
post:
summary: Execute a workflow
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -400,7 +463,7 @@ components:
- details_url
- created_at
- updated_at

GithubOrganization:
type: object
additionalProperties: false
Expand Down Expand Up @@ -618,6 +681,7 @@ components:
- html_url
- created_at
- updated_at

Project:
type: object
additionalProperties: false
Expand Down Expand Up @@ -741,6 +805,7 @@ components:
- name
- created_at
- updated_at

ErrorObject:
type: object
properties:
Expand Down
Loading