Skip to content

Commit e6a8bd7

Browse files
authored
Merge pull request #240 from OpenPathfinder/ulises/v1-list-workflows
2 parents 35ee87b + fcb32fb commit e6a8bd7

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

__tests__/httpServer/apiV1.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { resetDatabase, initializeStore } = require('../../__utils__')
66
const pkg = require('../../package.json')
77
const serverModule = require('../../src/httpServer')
88
const { dbSettings } = getConfig('test')
9+
const { getAllWorkflows } = require('../../src/cli/workflows')
910
let server
1011
let serverStop
1112
let app
@@ -115,6 +116,17 @@ describe('HTTP Server API V1', () => {
115116
test.todo('should return 500 for internal server error')
116117
})
117118

119+
describe('GET /api/v1/workflow', () => {
120+
test('should return 200 and a list of workflows', async () => {
121+
const response = await app.get('/api/v1/workflow')
122+
123+
expect(response.status).toBe(200)
124+
expect(response.body).toStrictEqual(getAllWorkflows())
125+
})
126+
127+
test.todo('should return 500 for internal server error')
128+
})
129+
118130
describe('POST /api/v1/generate-reports', () => {
119131
test('should return status completed when report generation succeeds', async () => {
120132
generateStaticReports.mockResolvedValueOnce()

src/cli/workflows.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const commandList = [{
3131
workflow: bulkImport
3232
}]
3333

34+
const workflows = commandList.map(({ name, description }) => ({ id: name, description }))
35+
3436
const validCommandNames = commandList.map(({ name }) => name)
3537

3638
function listWorkflowCommand (options = {}) {
@@ -70,5 +72,6 @@ async function runWorkflowCommand (knex, options = {}) {
7072

7173
module.exports = {
7274
listWorkflowCommand,
75+
getAllWorkflows: () => workflows,
7376
runWorkflowCommand
7477
}

src/httpServer/routers/apiV1.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { logger } = require('../../utils')
44
const { initializeStore } = require('../../store')
55
const _ = require('lodash')
66
const { isSlug } = require('validator')
7+
const { getAllWorkflows } = require('../../cli/workflows')
78

89
function createApiRouter (knex, express) {
910
const { addProject, getProjectByName } = initializeStore(knex)
@@ -42,6 +43,16 @@ function createApiRouter (knex, express) {
4243
}
4344
})
4445

46+
router.get('/workflow', (req, res) => {
47+
try {
48+
const workflows = getAllWorkflows()
49+
res.json(workflows)
50+
} catch (error) {
51+
logger.error(error)
52+
res.status(500).json({ errors: [{ message: 'Failed to retrieve workflows' }] })
53+
}
54+
})
55+
4556
router.post('/generate-reports', async (req, res) => {
4657
const startTs = new Date().toISOString()
4758
try {

src/httpServer/swagger/api-v1.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,37 @@ paths:
3939
- timestamp
4040
- name
4141
- version
42-
42+
/api/v1/workflow:
43+
get:
44+
summary: List all workflows
45+
description: Returns a list of all workflows in the system
46+
operationId: listWorkflows
47+
tags:
48+
- Workflows
49+
responses:
50+
'200':
51+
description: A list of workflows
52+
content:
53+
application/json:
54+
schema:
55+
type: array
56+
items:
57+
type: object
58+
additionalProperties: false
59+
properties:
60+
id:
61+
type: string
62+
example: example-workflow
63+
description:
64+
type: string
65+
example: This is an example workflow
66+
'500':
67+
description: Internal server error
68+
content:
69+
application/json:
70+
schema:
71+
$ref: '#/components/schemas/ErrorResponse'
72+
4373
/api/v1/project:
4474
post:
4575
summary: Create a new project

0 commit comments

Comments
 (0)