@@ -20,7 +20,6 @@ jest.mock('../../src/cli/workflows', () => ({
2020} ) )
2121
2222const request = require ( 'supertest' )
23- const { generateStaticReports } = require ( '../../src/reports' )
2423const knexInit = require ( 'knex' )
2524const { getConfig } = require ( '../../src/config' )
2625const { resetDatabase, initializeStore } = require ( '../../__utils__' )
@@ -183,7 +182,8 @@ describe('HTTP Server API V1', () => {
183182 id : 'test-workflow' ,
184183 description : 'Test workflow'
185184 } )
186- expect ( mockWorkflowFn ) . toHaveBeenCalledWith ( { some : 'data' } )
185+ // The first argument (...calls[0][0]) is Knex and we ignore it due framework limitations
186+ expect ( mockWorkflowFn . mock . calls [ 0 ] [ 1 ] ) . toEqual ( { some : 'data' } )
187187 } )
188188
189189 test ( 'should return 404 for invalid workflow ID' , async ( ) => {
@@ -216,47 +216,10 @@ describe('HTTP Server API V1', () => {
216216 description : 'Test workflow'
217217 } )
218218 expect ( response . body . errors [ 0 ] . message ) . toMatch ( / F a i l e d t o r u n w o r k f l o w : S o m e t h i n g w e n t w r o n g / )
219- expect ( mockWorkflowFn ) . toHaveBeenCalledWith ( { some : 'data' } )
219+ // The first argument (...calls[0][0]) is Knex and we ignore it due framework limitations
220+ expect ( mockWorkflowFn . mock . calls [ 0 ] [ 1 ] ) . toEqual ( { some : 'data' } )
220221 } )
221222
222223 test . todo ( 'should return 500 when workflow execution times out' )
223224 } )
224-
225- describe ( 'POST /api/v1/generate-reports' , ( ) => {
226- test ( 'should return status completed when report generation succeeds' , async ( ) => {
227- generateStaticReports . mockResolvedValueOnce ( )
228-
229- const response = await app . post ( '/api/v1/generate-reports' )
230-
231- expect ( generateStaticReports ) . toHaveBeenCalledWith ( expect . anything ( ) , { clearPreviousReports : true } )
232- expect ( response . status ) . toBe ( 202 )
233- expect ( response . body ) . toHaveProperty ( 'status' , 'completed' )
234- expect ( response . body ) . toHaveProperty ( 'startedAt' )
235- expect ( response . body ) . toHaveProperty ( 'finishedAt' )
236-
237- const startedAt = new Date ( response . body . startedAt )
238- const finishedAt = new Date ( response . body . finishedAt )
239- expect ( startedAt . toISOString ( ) ) . toBe ( response . body . startedAt )
240- expect ( finishedAt . toISOString ( ) ) . toBe ( response . body . finishedAt )
241- expect ( finishedAt . getTime ( ) ) . toBeGreaterThanOrEqual ( startedAt . getTime ( ) )
242- } )
243-
244- test ( 'should return status failed when report generation fails' , async ( ) => {
245- generateStaticReports . mockRejectedValueOnce ( new Error ( 'Report generation failed' ) )
246-
247- const response = await app . post ( '/api/v1/generate-reports' )
248-
249- expect ( generateStaticReports ) . toHaveBeenCalledWith ( expect . anything ( ) , { clearPreviousReports : true } )
250- expect ( response . status ) . toBe ( 500 )
251- expect ( response . body ) . toHaveProperty ( 'status' , 'failed' )
252- expect ( response . body ) . toHaveProperty ( 'startedAt' )
253- expect ( response . body ) . toHaveProperty ( 'finishedAt' )
254-
255- const startedAt = new Date ( response . body . startedAt )
256- const finishedAt = new Date ( response . body . finishedAt )
257- expect ( startedAt . toISOString ( ) ) . toBe ( response . body . startedAt )
258- expect ( finishedAt . toISOString ( ) ) . toBe ( response . body . finishedAt )
259- expect ( finishedAt . getTime ( ) ) . toBeGreaterThanOrEqual ( startedAt . getTime ( ) )
260- } )
261- } )
262225} )
0 commit comments