Skip to content

Commit 2efd18c

Browse files
committed
feat: remove POST /api/v1/generate-reports endpoint
This now can be achieved by running `curl -X POST http://localhost:3000/api/v1/workflow/generate-reports/run -H "Content-Type: application/json"`
1 parent b3de0ab commit 2efd18c

File tree

3 files changed

+0
-114
lines changed

3 files changed

+0
-114
lines changed

__tests__/httpServer/apiV1.test.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jest.mock('../../src/cli/workflows', () => ({
2020
}))
2121

2222
const request = require('supertest')
23-
const { generateStaticReports } = require('../../src/reports')
2423
const knexInit = require('knex')
2524
const { getConfig } = require('../../src/config')
2625
const { resetDatabase, initializeStore } = require('../../__utils__')
@@ -223,42 +222,4 @@ describe('HTTP Server API V1', () => {
223222

224223
test.todo('should return 500 when workflow execution times out')
225224
})
226-
227-
describe('POST /api/v1/generate-reports', () => {
228-
test('should return status completed when report generation succeeds', async () => {
229-
generateStaticReports.mockResolvedValueOnce()
230-
231-
const response = await app.post('/api/v1/generate-reports')
232-
233-
expect(generateStaticReports).toHaveBeenCalledWith(expect.anything(), { clearPreviousReports: true })
234-
expect(response.status).toBe(202)
235-
expect(response.body).toHaveProperty('status', 'completed')
236-
expect(response.body).toHaveProperty('startedAt')
237-
expect(response.body).toHaveProperty('finishedAt')
238-
239-
const startedAt = new Date(response.body.startedAt)
240-
const finishedAt = new Date(response.body.finishedAt)
241-
expect(startedAt.toISOString()).toBe(response.body.startedAt)
242-
expect(finishedAt.toISOString()).toBe(response.body.finishedAt)
243-
expect(finishedAt.getTime()).toBeGreaterThanOrEqual(startedAt.getTime())
244-
})
245-
246-
test('should return status failed when report generation fails', async () => {
247-
generateStaticReports.mockRejectedValueOnce(new Error('Report generation failed'))
248-
249-
const response = await app.post('/api/v1/generate-reports')
250-
251-
expect(generateStaticReports).toHaveBeenCalledWith(expect.anything(), { clearPreviousReports: true })
252-
expect(response.status).toBe(500)
253-
expect(response.body).toHaveProperty('status', 'failed')
254-
expect(response.body).toHaveProperty('startedAt')
255-
expect(response.body).toHaveProperty('finishedAt')
256-
257-
const startedAt = new Date(response.body.startedAt)
258-
const finishedAt = new Date(response.body.finishedAt)
259-
expect(startedAt.toISOString()).toBe(response.body.startedAt)
260-
expect(finishedAt.toISOString()).toBe(response.body.finishedAt)
261-
expect(finishedAt.getTime()).toBeGreaterThanOrEqual(startedAt.getTime())
262-
})
263-
})
264225
})

src/httpServer/routers/apiV1.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { generateStaticReports } = require('../../reports')
21
const pkg = require('../../../package.json')
32
const { logger } = require('../../utils')
43
const { initializeStore } = require('../../store')
@@ -105,24 +104,6 @@ function createApiRouter (knex, express) {
105104
}
106105
})
107106

108-
router.post('/generate-reports', async (req, res) => {
109-
const startTs = new Date().toISOString()
110-
try {
111-
await generateStaticReports(knex, { clearPreviousReports: true })
112-
res.status(202).json({
113-
status: 'completed',
114-
startedAt: startTs,
115-
finishedAt: new Date().toISOString()
116-
})
117-
} catch (error) {
118-
logger.error(error)
119-
res.status(500).json({
120-
status: 'failed',
121-
startedAt: startTs,
122-
finishedAt: new Date().toISOString()
123-
})
124-
}
125-
})
126107
return router
127108
}
128109

src/httpServer/swagger/api-v1.yml

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -197,62 +197,6 @@ paths:
197197
application/json:
198198
schema:
199199
$ref: '#/components/schemas/ErrorResponse'
200-
/api/v1/generate-reports:
201-
post:
202-
summary: Generate static reports
203-
description: Triggers the generation of static reports
204-
operationId: generateReports
205-
tags:
206-
- Reports
207-
responses:
208-
'202':
209-
description: Report generation accepted
210-
content:
211-
application/json:
212-
schema:
213-
type: object
214-
additionalProperties: false
215-
properties:
216-
status:
217-
type: string
218-
enum: [completed, failed]
219-
example: completed
220-
startedAt:
221-
type: string
222-
format: date-time
223-
example: '2025-05-03T07:20:16.000Z'
224-
finishedAt:
225-
type: string
226-
format: date-time
227-
example: '2025-05-03T07:20:20.000Z'
228-
required:
229-
- status
230-
- startedAt
231-
- finishedAt
232-
'500':
233-
description: Report generation failed
234-
content:
235-
application/json:
236-
schema:
237-
type: object
238-
additionalProperties: false
239-
properties:
240-
status:
241-
type: string
242-
enum: [failed]
243-
example: failed
244-
startedAt:
245-
type: string
246-
format: date-time
247-
example: '2025-05-03T07:20:16.000Z'
248-
finishedAt:
249-
type: string
250-
format: date-time
251-
example: '2025-05-03T07:20:20.000Z'
252-
required:
253-
- status
254-
- startedAt
255-
- finishedAt
256200

257201
components:
258202
schemas:

0 commit comments

Comments
 (0)