1
1
import { randomUUID } from 'crypto' ;
2
2
import anyTest , { TestFn } from 'ava' ;
3
3
import asyncRetry from 'async-retry' ;
4
- import { Client , defaultPayloadConverter } from '@temporalio/client' ;
4
+ import {
5
+ Client ,
6
+ defaultPayloadConverter ,
7
+ CalendarSpec ,
8
+ CalendarSpecDescription ,
9
+ ScheduleHandle ,
10
+ ScheduleSummary ,
11
+ ScheduleUpdateOptions ,
12
+ } from '@temporalio/client' ;
5
13
import { msToNumber } from '@temporalio/common/lib/time' ;
6
- import { CalendarSpec , CalendarSpecDescription , ScheduleSummary } from '@temporalio/client/lib/schedule-types' ;
7
- import { ScheduleHandle } from '@temporalio/client/lib/schedule-client' ;
8
14
import { RUN_INTEGRATION_TESTS } from './helpers' ;
9
15
10
16
export interface Context {
@@ -15,7 +21,8 @@ const taskQueue = 'async-activity-completion';
15
21
const test = anyTest as TestFn < Context > ;
16
22
17
23
const dummyWorkflow = async ( ) => undefined ;
18
- const dummyWorkflow2 = async ( _x ?: string ) => undefined ;
24
+ const dummyWorkflowWith1Arg = async ( _s : string ) => undefined ;
25
+ const dummyWorkflowWith2Args = async ( _x : number , _y : number ) => undefined ;
19
26
20
27
const calendarSpecDescriptionDefaults : CalendarSpecDescription = {
21
28
second : [ { start : 0 , end : 0 , step : 1 } ] ,
@@ -29,7 +36,7 @@ const calendarSpecDescriptionDefaults: CalendarSpecDescription = {
29
36
} ;
30
37
31
38
if ( RUN_INTEGRATION_TESTS ) {
32
- test . before ( async ( t ) => {
39
+ test . beforeEach ( async ( t ) => {
33
40
t . context = {
34
41
client : new Client ( ) ,
35
42
} ;
@@ -115,7 +122,7 @@ if (RUN_INTEGRATION_TESTS) {
115
122
}
116
123
} ) ;
117
124
118
- test ( 'Can create schedule with startWorkflow action' , async ( t ) => {
125
+ test ( 'Can create schedule with startWorkflow action (no arg) ' , async ( t ) => {
119
126
const { client } = t . context ;
120
127
const scheduleId = `can-create-schedule-with-startWorkflow-action-${ randomUUID ( ) } ` ;
121
128
const handle = await client . schedule . create ( {
@@ -148,6 +155,41 @@ if (RUN_INTEGRATION_TESTS) {
148
155
}
149
156
} ) ;
150
157
158
+ test ( 'Can create schedule with startWorkflow action (with args)' , async ( t ) => {
159
+ const { client } = t . context ;
160
+ const scheduleId = `can-create-schedule-with-startWorkflow-action-${ randomUUID ( ) } ` ;
161
+ const handle = await client . schedule . create ( {
162
+ scheduleId,
163
+ spec : {
164
+ calendars : [ { hour : { start : 2 , end : 7 , step : 1 } } ] ,
165
+ } ,
166
+ action : {
167
+ type : 'startWorkflow' ,
168
+ workflowType : dummyWorkflowWith2Args ,
169
+ args : [ 3 , 4 ] ,
170
+ taskQueue,
171
+ memo : {
172
+ 'my-memo' : 'foo' ,
173
+ } ,
174
+ searchAttributes : {
175
+ CustomKeywordField : [ 'test-value2' ] ,
176
+ } ,
177
+ } ,
178
+ } ) ;
179
+
180
+ try {
181
+ const describedSchedule = await handle . describe ( ) ;
182
+
183
+ t . is ( describedSchedule . action . type , 'startWorkflow' ) ;
184
+ t . is ( describedSchedule . action . workflowType , 'dummyWorkflowWith2Args' ) ;
185
+ t . deepEqual ( describedSchedule . action . args , [ 3 , 4 ] ) ;
186
+ t . deepEqual ( describedSchedule . action . memo , { 'my-memo' : 'foo' } ) ;
187
+ t . deepEqual ( describedSchedule . action . searchAttributes ?. CustomKeywordField , [ 'test-value2' ] ) ;
188
+ } finally {
189
+ await handle . delete ( ) ;
190
+ }
191
+ } ) ;
192
+
151
193
test ( 'Interceptor is called on create schedule' , async ( t ) => {
152
194
const clientWithInterceptor = new Client ( {
153
195
connection : t . context . client . connection ,
@@ -272,9 +314,9 @@ if (RUN_INTEGRATION_TESTS) {
272
314
}
273
315
} ) ;
274
316
275
- test ( 'Can update schedule' , async ( t ) => {
317
+ test ( 'Can update schedule calendar ' , async ( t ) => {
276
318
const { client } = t . context ;
277
- const scheduleId = `can-update-schedule-${ randomUUID ( ) } ` ;
319
+ const scheduleId = `can-update-schedule-calendar- ${ randomUUID ( ) } ` ;
278
320
const handle = await client . schedule . create ( {
279
321
scheduleId,
280
322
spec : {
@@ -315,7 +357,8 @@ if (RUN_INTEGRATION_TESTS) {
315
357
action : {
316
358
type : 'startWorkflow' ,
317
359
workflowId : `${ scheduleId } -workflow` ,
318
- workflowType : dummyWorkflow ,
360
+ workflowType : dummyWorkflowWith1Arg ,
361
+ args : [ 'foo' ] ,
319
362
taskQueue,
320
363
} ,
321
364
} ) ;
@@ -326,16 +369,48 @@ if (RUN_INTEGRATION_TESTS) {
326
369
action : {
327
370
type : 'startWorkflow' ,
328
371
workflowId : `${ scheduleId } -workflow-2` ,
329
- workflowType : dummyWorkflow2 ,
330
- args : [ 'updated' ] ,
372
+ workflowType : dummyWorkflowWith2Args ,
373
+ args : [ 3 , 4 ] ,
331
374
taskQueue,
332
375
} ,
333
376
} ) ) ;
334
377
335
378
const describedSchedule = await handle . describe ( ) ;
336
379
t . is ( describedSchedule . action . type , 'startWorkflow' ) ;
337
- t . is ( describedSchedule . action . workflowType , 'dummyWorkflow2' ) ;
338
- t . deepEqual ( describedSchedule . action . args , [ 'updated' ] ) ;
380
+ t . is ( describedSchedule . action . workflowType , 'dummyWorkflowWith2Args' ) ;
381
+ t . deepEqual ( describedSchedule . action . args , [ 3 , 4 ] ) ;
382
+ } finally {
383
+ await handle . delete ( ) ;
384
+ }
385
+ } ) ;
386
+
387
+ test ( 'Can update schedule intervals' , async ( t ) => {
388
+ const { client } = t . context ;
389
+ const scheduleId = `can-update-schedule-intervals-${ randomUUID ( ) } ` ;
390
+ const handle = await client . schedule . create ( {
391
+ scheduleId,
392
+ spec : {
393
+ intervals : [ { every : '5h' } ] ,
394
+ } ,
395
+ action : {
396
+ type : 'startWorkflow' ,
397
+ workflowId : `${ scheduleId } -workflow` ,
398
+ workflowType : dummyWorkflowWith1Arg ,
399
+ args : [ 'foo' ] ,
400
+ taskQueue,
401
+ } ,
402
+ } ) ;
403
+
404
+ try {
405
+ await handle . update ( ( x : ScheduleUpdateOptions ) => {
406
+ x . spec . intervals = [ { every : '3h' } ] ;
407
+ return x ;
408
+ } ) ;
409
+
410
+ const describedSchedule = await handle . describe ( ) ;
411
+ t . is ( describedSchedule . action . type , 'startWorkflow' ) ;
412
+ t . is ( describedSchedule . action . workflowType , 'dummyWorkflowWith1Arg' ) ;
413
+ t . deepEqual ( describedSchedule . action . args , [ 'foo' ] ) ;
339
414
} finally {
340
415
await handle . delete ( ) ;
341
416
}
0 commit comments