@@ -2,10 +2,16 @@ import { FatalError } from '@workflow/errors';
22import { describe , expect , it } from 'vitest' ;
33import {
44 type HookInvocationQueueItem ,
5+ type QueueItem ,
56 type StepInvocationQueueItem ,
67 WorkflowSuspension ,
78} from './global.js' ;
89
10+ // Helper to convert array of queue items to Map keyed by correlationId
11+ function toQueueMap ( items : QueueItem [ ] ) : Map < string , QueueItem > {
12+ return new Map ( items . map ( ( item ) => [ item . correlationId , item ] ) ) ;
13+ }
14+
915describe ( 'FatalError' , ( ) => {
1016 it ( 'should create a FatalError instance' , ( ) => {
1117 const error = new FatalError ( 'Test fatal error' ) ;
@@ -43,7 +49,7 @@ describe('WorkflowSuspension', () => {
4349 correlationId : 'inv-1' ,
4450 } ,
4551 ] ;
46- const error = new WorkflowSuspension ( steps , globalThis ) ;
52+ const error = new WorkflowSuspension ( toQueueMap ( steps ) , globalThis ) ;
4753
4854 expect ( error ) . toBeInstanceOf ( WorkflowSuspension ) ;
4955 expect ( error ) . toBeInstanceOf ( Error ) ;
@@ -60,7 +66,7 @@ describe('WorkflowSuspension', () => {
6066 correlationId : 'inv-1' ,
6167 } ,
6268 ] ;
63- const error = new WorkflowSuspension ( steps , globalThis ) ;
69+ const error = new WorkflowSuspension ( toQueueMap ( steps ) , globalThis ) ;
6470
6571 expect ( error . message ) . toBe ( '1 step has not been run yet' ) ;
6672 } ) ;
@@ -80,14 +86,14 @@ describe('WorkflowSuspension', () => {
8086 correlationId : 'inv-2' ,
8187 } ,
8288 ] ;
83- const error = new WorkflowSuspension ( steps , globalThis ) ;
89+ const error = new WorkflowSuspension ( toQueueMap ( steps ) , globalThis ) ;
8490
8591 expect ( error . message ) . toBe ( '2 steps have not been run yet' ) ;
8692 } ) ;
8793
8894 it ( 'should handle empty steps array' , ( ) => {
8995 const steps : StepInvocationQueueItem [ ] = [ ] ;
90- const error = new WorkflowSuspension ( steps , globalThis ) ;
96+ const error = new WorkflowSuspension ( toQueueMap ( steps ) , globalThis ) ;
9197
9298 expect ( error . steps ) . toEqual ( [ ] ) ;
9399 expect ( error . message ) . toBe ( '0 steps have not been run yet' ) ;
@@ -115,7 +121,7 @@ describe('WorkflowSuspension', () => {
115121 correlationId : 'another-inv' ,
116122 } ,
117123 ] ;
118- const error = new WorkflowSuspension ( complexSteps , globalThis ) ;
124+ const error = new WorkflowSuspension ( toQueueMap ( complexSteps ) , globalThis ) ;
119125
120126 expect ( error . steps ) . toEqual ( complexSteps ) ;
121127 expect ( error . message ) . toBe ( '2 steps have not been run yet' ) ;
@@ -142,7 +148,7 @@ describe('WorkflowSuspension', () => {
142148 correlationId : 'inv-1' ,
143149 } ,
144150 ] ;
145- const error = new WorkflowSuspension ( steps , globalThis ) ;
151+ const error = new WorkflowSuspension ( toQueueMap ( steps ) , globalThis ) ;
146152
147153 expect ( error instanceof Error ) . toBe ( true ) ;
148154 expect ( error instanceof WorkflowSuspension ) . toBe ( true ) ;
@@ -158,7 +164,7 @@ describe('WorkflowSuspension', () => {
158164 correlationId : 'inv-1' ,
159165 } ,
160166 ] ;
161- const error = new WorkflowSuspension ( steps , globalThis ) ;
167+ const error = new WorkflowSuspension ( toQueueMap ( steps ) , globalThis ) ;
162168
163169 expect ( error . stack ) . toBeDefined ( ) ;
164170 expect ( error . stack ) . toContain ( 'WorkflowSuspension' ) ;
@@ -179,7 +185,7 @@ describe('WorkflowSuspension', () => {
179185 correlationId : 'email-456' ,
180186 } ,
181187 ] ;
182- const error = new WorkflowSuspension ( steps , globalThis ) ;
188+ const error = new WorkflowSuspension ( toQueueMap ( steps ) , globalThis ) ;
183189
184190 expect ( error . steps ) . toHaveLength ( 2 ) ;
185191 expect ( ( error . steps [ 0 ] as StepInvocationQueueItem ) . stepName ) . toBe (
@@ -212,7 +218,7 @@ describe('WorkflowSuspension', () => {
212218 token : 'webhook-token' ,
213219 } ,
214220 ] ;
215- const error = new WorkflowSuspension ( hooks , globalThis ) ;
221+ const error = new WorkflowSuspension ( toQueueMap ( hooks ) , globalThis ) ;
216222
217223 expect ( error . message ) . toBe ( '1 hook has not been created yet' ) ;
218224 expect ( error . hookCount ) . toBe ( 1 ) ;
@@ -231,7 +237,7 @@ describe('WorkflowSuspension', () => {
231237 token : 'webhook-token-2' ,
232238 } ,
233239 ] ;
234- const error = new WorkflowSuspension ( hooks , globalThis ) ;
240+ const error = new WorkflowSuspension ( toQueueMap ( hooks ) , globalThis ) ;
235241
236242 expect ( error . message ) . toBe ( '2 hooks have not been created yet' ) ;
237243 expect ( error . hookCount ) . toBe ( 2 ) ;
@@ -245,7 +251,7 @@ describe('WorkflowSuspension', () => {
245251 token : 'my-token' ,
246252 } ,
247253 ] ;
248- const error = new WorkflowSuspension ( hooks , globalThis ) ;
254+ const error = new WorkflowSuspension ( toQueueMap ( hooks ) , globalThis ) ;
249255
250256 expect ( error . message ) . toBe ( '1 hook has not been created yet' ) ;
251257 expect ( error . hookCount ) . toBe ( 1 ) ;
@@ -264,7 +270,7 @@ describe('WorkflowSuspension', () => {
264270 token : 'token-2' ,
265271 } ,
266272 ] ;
267- const error = new WorkflowSuspension ( hooks , globalThis ) ;
273+ const error = new WorkflowSuspension ( toQueueMap ( hooks ) , globalThis ) ;
268274
269275 expect ( error . message ) . toBe ( '2 hooks have not been created yet' ) ;
270276 expect ( error . hookCount ) . toBe ( 2 ) ;
@@ -289,7 +295,7 @@ describe('WorkflowSuspension', () => {
289295 token : 'my-token' ,
290296 } ,
291297 ] ;
292- const error = new WorkflowSuspension ( items , globalThis ) ;
298+ const error = new WorkflowSuspension ( toQueueMap ( items ) , globalThis ) ;
293299
294300 expect ( error . message ) . toBe ( '1 step and 2 hooks have not been run yet' ) ;
295301 expect ( error . stepCount ) . toBe ( 1 ) ;
@@ -316,7 +322,7 @@ describe('WorkflowSuspension', () => {
316322 token : 'webhook-token' ,
317323 } ,
318324 ] ;
319- const error = new WorkflowSuspension ( items , globalThis ) ;
325+ const error = new WorkflowSuspension ( toQueueMap ( items ) , globalThis ) ;
320326
321327 expect ( error . message ) . toBe ( '2 steps and 1 hook have not been run yet' ) ;
322328 expect ( error . stepCount ) . toBe ( 2 ) ;
@@ -337,7 +343,7 @@ describe('WorkflowSuspension', () => {
337343 token : 'my-token' ,
338344 } ,
339345 ] ;
340- const error = new WorkflowSuspension ( items , globalThis ) ;
346+ const error = new WorkflowSuspension ( toQueueMap ( items ) , globalThis ) ;
341347
342348 // When there are steps, the action should be "run" not "created"
343349 expect ( error . message ) . toBe ( '1 step and 1 hook have not been run yet' ) ;
@@ -351,7 +357,7 @@ describe('WorkflowSuspension', () => {
351357 token : 'webhook-token' ,
352358 } ,
353359 ] ;
354- const error = new WorkflowSuspension ( hooks , globalThis ) ;
360+ const error = new WorkflowSuspension ( toQueueMap ( hooks ) , globalThis ) ;
355361
356362 expect ( error . message ) . toBe ( '1 hook has not been created yet' ) ;
357363 } ) ;
@@ -364,7 +370,7 @@ describe('WorkflowSuspension', () => {
364370 token : 'my-token' ,
365371 } ,
366372 ] ;
367- const error = new WorkflowSuspension ( hooks , globalThis ) ;
373+ const error = new WorkflowSuspension ( toQueueMap ( hooks ) , globalThis ) ;
368374
369375 expect ( error . message ) . toBe ( '1 hook has not been created yet' ) ;
370376 } ) ;
0 commit comments