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
12 changes: 12 additions & 0 deletions __tests__/httpServer/apiV1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { resetDatabase, initializeStore } = require('../../__utils__')
const pkg = require('../../package.json')
const serverModule = require('../../src/httpServer')
const { dbSettings } = getConfig('test')
const { getAllWorkflows } = require('../../src/cli/workflows')
let server
let serverStop
let app
Expand Down Expand Up @@ -115,6 +116,17 @@ describe('HTTP Server API V1', () => {
test.todo('should return 500 for internal server error')
})

describe('GET /api/v1/workflow', () => {
test('should return 200 and a list of workflows', async () => {
const response = await app.get('/api/v1/workflow')

expect(response.status).toBe(200)
expect(response.body).toStrictEqual(getAllWorkflows())
})

test.todo('should return 500 for internal server error')
})

describe('POST /api/v1/generate-reports', () => {
test('should return status completed when report generation succeeds', async () => {
generateStaticReports.mockResolvedValueOnce()
Expand Down
3 changes: 3 additions & 0 deletions src/cli/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const commandList = [{
workflow: bulkImport
}]

const workflows = commandList.map(({ name, description }) => ({ id: name, description }))

const validCommandNames = commandList.map(({ name }) => name)

function listWorkflowCommand (options = {}) {
Expand Down Expand Up @@ -70,5 +72,6 @@ async function runWorkflowCommand (knex, options = {}) {

module.exports = {
listWorkflowCommand,
getAllWorkflows: () => workflows,
runWorkflowCommand
}
11 changes: 11 additions & 0 deletions src/httpServer/routers/apiV1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { logger } = require('../../utils')
const { initializeStore } = require('../../store')
const _ = require('lodash')
const { isSlug } = require('validator')
const { getAllWorkflows } = require('../../cli/workflows')

function createApiRouter (knex, express) {
const { addProject, getProjectByName } = initializeStore(knex)
Expand Down Expand Up @@ -42,6 +43,16 @@ function createApiRouter (knex, express) {
}
})

router.get('/workflow', (req, res) => {
try {
const workflows = getAllWorkflows()
res.json(workflows)
} catch (error) {
logger.error(error)
res.status(500).json({ errors: [{ message: 'Failed to retrieve workflows' }] })
}
})

router.post('/generate-reports', async (req, res) => {
const startTs = new Date().toISOString()
try {
Expand Down
32 changes: 31 additions & 1 deletion src/httpServer/swagger/api-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,37 @@ paths:
- timestamp
- name
- version

/api/v1/workflow:
get:
summary: List all workflows
description: Returns a list of all workflows in the system
operationId: listWorkflows
tags:
- Workflows
responses:
'200':
description: A list of workflows
content:
application/json:
schema:
type: array
items:
type: object
additionalProperties: false
properties:
id:
type: string
example: example-workflow
description:
type: string
example: This is an example workflow
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

/api/v1/project:
post:
summary: Create a new project
Expand Down
Loading