1+ const saveRequestBodyMock = jest . fn ( ) ;
12import { progressService } from '../../src/lib/services/progress.service' ;
2- import { logger } from '@openops/server-shared' ;
33import { throwIfExecutionTimeExceeded } from '../../src/lib/timeout-validator' ;
44
55jest . mock ( '@openops/server-shared' , ( ) => ( {
66 ...jest . requireActual ( '@openops/server-shared' ) ,
7+ saveRequestBody : saveRequestBodyMock ,
78 logger : {
89 debug : jest . fn ( ) ,
910 error : jest . fn ( ) ,
@@ -44,12 +45,12 @@ describe('Progress Service', () => {
4445
4546 beforeEach ( ( ) => {
4647 jest . clearAllMocks ( ) ;
47-
48+
4849 // Reset the timeout mock to not throw by default
4950 mockThrowIfExecutionTimeExceeded . mockReset ( ) ;
50-
51+
5152 mockMakeHttpRequest . mockResolvedValue ( { } ) ;
52-
53+
5354 // Reset the global lastRequestHash by calling with unique params
5455 // This ensures no deduplication issues between tests
5556 jest . clearAllMocks ( ) ;
@@ -69,18 +70,23 @@ describe('Progress Service', () => {
6970 } ,
7071 } ;
7172
73+ saveRequestBodyMock . mockResolvedValue ( 'request:test-run-id' ) ;
7274 await progressService . sendUpdate ( successParams ) ;
7375
76+ expect ( saveRequestBodyMock ) . toHaveBeenCalledWith ( 'test-run-id' , expect . objectContaining ( {
77+ executionCorrelationId : 'test-correlation-id-success' ,
78+ runId : 'test-run-id' ,
79+ workerHandlerId : 'test-handler-id' ,
80+ progressUpdateType : 'WEBHOOK_RESPONSE' ,
81+ } ) ) ;
82+
7483 expect ( successParams . flowExecutorContext . toResponse ) . toHaveBeenCalled ( ) ;
7584 expect ( mockMakeHttpRequest ) . toHaveBeenCalledWith (
7685 'POST' ,
7786 'http://localhost:3000/v1/engine/update-run' ,
7887 expect . any ( Object ) ,
7988 expect . objectContaining ( {
80- executionCorrelationId : 'test-correlation-id-success' ,
81- runId : 'test-run-id' ,
82- workerHandlerId : 'test-handler-id' ,
83- progressUpdateType : 'WEBHOOK_RESPONSE' ,
89+ bodyAccessKey : 'request:test-run-id' ,
8490 } ) ,
8591 expect . objectContaining ( {
8692 retries : 3 ,
@@ -98,8 +104,22 @@ describe('Progress Service', () => {
98104 } ,
99105 } ;
100106
107+ saveRequestBodyMock . mockResolvedValue ( 'request:test-run-id' ) ;
101108 await progressService . sendUpdate ( uniqueParams ) ;
102109
110+ expect ( saveRequestBodyMock ) . toHaveBeenCalledWith ( 'test-run-id' , expect . objectContaining ( {
111+ executionCorrelationId : 'test-correlation-id-payload' ,
112+ runId : 'test-run-id' ,
113+ workerHandlerId : 'test-handler-id' ,
114+ progressUpdateType : 'WEBHOOK_RESPONSE' ,
115+ runDetails : expect . objectContaining ( {
116+ steps : { } ,
117+ status : 'RUNNING' ,
118+ duration : 1000 ,
119+ tasks : 1 ,
120+ } ) ,
121+ } ) ) ;
122+
103123 expect ( mockMakeHttpRequest ) . toHaveBeenCalledTimes ( 1 ) ;
104124 const call = mockMakeHttpRequest . mock . calls [ 0 ] ;
105125 const [ method , url , _ , requestBody ] = call ;
@@ -108,16 +128,7 @@ describe('Progress Service', () => {
108128 expect ( url ) . toBe ( 'http://localhost:3000/v1/engine/update-run' ) ;
109129 expect ( requestBody ) . toEqual (
110130 expect . objectContaining ( {
111- executionCorrelationId : 'test-correlation-id-payload' ,
112- runId : 'test-run-id' ,
113- workerHandlerId : 'test-handler-id' ,
114- progressUpdateType : 'WEBHOOK_RESPONSE' ,
115- runDetails : expect . objectContaining ( {
116- steps : { } ,
117- status : 'RUNNING' ,
118- duration : 1000 ,
119- tasks : 1 ,
120- } ) ,
131+ bodyAccessKey : 'request:test-run-id' ,
121132 } )
122133 ) ;
123134 } ) ;
@@ -132,13 +143,30 @@ describe('Progress Service', () => {
132143 } ,
133144 } ;
134145
146+ saveRequestBodyMock . mockResolvedValue ( 'request:test-run-id' ) ;
135147 await progressService . sendUpdate ( paramsWithoutHandlerId ) ;
136148
149+ expect ( saveRequestBodyMock ) . toHaveBeenCalledWith ( 'test-run-id' , expect . objectContaining ( {
150+ executionCorrelationId : 'test-correlation-id-null-handler' ,
151+ runId : 'test-run-id' ,
152+ workerHandlerId : null ,
153+ progressUpdateType : 'WEBHOOK_RESPONSE' ,
154+ runDetails : expect . objectContaining ( {
155+ steps : { } ,
156+ status : 'RUNNING' ,
157+ duration : 1000 ,
158+ tasks : 1 ,
159+ } ) ,
160+ } ) ) ;
161+
137162 expect ( mockMakeHttpRequest ) . toHaveBeenCalledTimes ( 1 ) ;
138163 const call = mockMakeHttpRequest . mock . calls [ 0 ] ;
139164 const [ _ , __ , ___ , requestBody ] = call ;
140-
141- expect ( requestBody . workerHandlerId ) . toBe ( null ) ;
165+
166+ expect ( requestBody ) . toEqual ( {
167+ bodyAccessKey : 'request:test-run-id' ,
168+ }
169+ ) ;
142170 } ) ;
143171
144172 it ( 'should deduplicate identical requests based on hash' , async ( ) => {
@@ -327,10 +355,10 @@ describe('Progress Service', () => {
327355 // Test the retry delay function
328356 const call = mockMakeHttpRequest . mock . calls [ 0 ] ;
329357 const [ _ , __ , ___ , ____ , options ] = call ;
330-
358+
331359 expect ( options . retryDelay ( 0 ) ) . toBe ( 200 ) ; // 1st retry: 200ms
332360 expect ( options . retryDelay ( 1 ) ) . toBe ( 400 ) ; // 2nd retry: 400ms
333361 expect ( options . retryDelay ( 2 ) ) . toBe ( 600 ) ; // 3rd retry: 600ms
334362 } ) ;
335363 } ) ;
336- } ) ;
364+ } ) ;
0 commit comments