forked from boringnode/queue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule.spec.ts
More file actions
641 lines (476 loc) · 21.5 KB
/
schedule.spec.ts
File metadata and controls
641 lines (476 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
import { test } from '@japa/runner'
import { memory } from './_mocks/memory_adapter.js'
import { QueueManager } from '../src/queue_manager.js'
import { ScheduleBuilder } from '../src/schedule_builder.js'
import { Schedule } from '../src/schedule.js'
import { Job } from '../src/job.js'
import { Locator } from '../src/locator.js'
import * as errors from '../src/exceptions.js'
test.group('ScheduleBuilder', (group) => {
group.each.setup(async () => {
const sharedAdapter = memory()()
await QueueManager.init({
default: 'memory',
adapters: { memory: () => sharedAdapter },
})
return () => QueueManager.destroy()
})
test('should create a schedule with cron expression', async ({ assert }) => {
const builder = new ScheduleBuilder('CleanupJob', { days: 30 })
const { scheduleId } = await builder.cron('0 0 * * *').run()
assert.isString(scheduleId)
const schedule = await Schedule.find(scheduleId)
assert.isNotNull(schedule)
assert.equal(schedule!.name, 'CleanupJob')
assert.deepEqual(schedule!.payload, { days: 30 })
assert.equal(schedule!.cronExpression, '0 0 * * *')
assert.isNull(schedule!.everyMs)
assert.equal(schedule!.timezone, 'UTC')
assert.equal(schedule!.status, 'active')
})
test('should create a schedule with interval using every()', async ({ assert }) => {
const builder = new ScheduleBuilder('SyncJob', { source: 'api' })
const { scheduleId } = await builder.every('5m').run()
assert.isString(scheduleId)
const schedule = await Schedule.find(scheduleId)
assert.isNotNull(schedule)
assert.equal(schedule!.name, 'SyncJob')
assert.equal(schedule!.everyMs, 5 * 60 * 1000)
assert.isNull(schedule!.cronExpression)
})
test('should use job name as default schedule id', async ({ assert }) => {
const builder = new ScheduleBuilder('DefaultIdJob', { test: true })
const { scheduleId } = await builder.every('1h').run()
assert.equal(scheduleId, 'DefaultIdJob')
const schedule = await Schedule.find('DefaultIdJob')
assert.isNotNull(schedule)
assert.equal(schedule!.id, 'DefaultIdJob')
})
test('should set custom schedule id for upsert behavior', async ({ assert }) => {
const builder = new ScheduleBuilder('CleanupJob', { days: 30 })
const { scheduleId } = await builder.id('cleanup-daily').cron('0 0 * * *').run()
assert.equal(scheduleId, 'cleanup-daily')
const schedule = await Schedule.find('cleanup-daily')
assert.isNotNull(schedule)
assert.equal(schedule!.id, 'cleanup-daily')
})
test('should upsert schedule when id already exists', async ({ assert }) => {
const builder1 = new ScheduleBuilder('CleanupJob', { days: 30 })
await builder1.id('cleanup-daily').cron('0 0 * * *').run()
// Update with new payload and cron
const builder2 = new ScheduleBuilder('CleanupJob', { days: 7 })
const { scheduleId } = await builder2.id('cleanup-daily').cron('0 12 * * *').run()
assert.equal(scheduleId, 'cleanup-daily')
const schedule = await Schedule.find('cleanup-daily')
assert.deepEqual(schedule!.payload, { days: 7 })
assert.equal(schedule!.cronExpression, '0 12 * * *')
})
test('should set timezone', async ({ assert }) => {
const builder = new ScheduleBuilder('ReportJob', {})
const { scheduleId } = await builder.cron('0 9 * * *').timezone('Europe/Paris').run()
const schedule = await Schedule.find(scheduleId)
assert.equal(schedule!.timezone, 'Europe/Paris')
})
test('should set start boundary with from()', async ({ assert }) => {
const fromDate = new Date('2025-01-01T00:00:00Z')
const builder = new ScheduleBuilder('CampaignJob', {})
const { scheduleId } = await builder.cron('0 0 * * *').from(fromDate).run()
const schedule = await Schedule.find(scheduleId)
assert.deepEqual(schedule!.from, fromDate)
})
test('should set end boundary with to()', async ({ assert }) => {
const toDate = new Date('2025-12-31T23:59:59Z')
const builder = new ScheduleBuilder('CampaignJob', {})
const { scheduleId } = await builder.cron('0 0 * * *').to(toDate).run()
const schedule = await Schedule.find(scheduleId)
assert.deepEqual(schedule!.to, toDate)
})
test('should set both boundaries with between()', async ({ assert }) => {
const fromDate = new Date('2025-01-01T00:00:00Z')
const toDate = new Date('2025-12-31T23:59:59Z')
const builder = new ScheduleBuilder('CampaignJob', {})
const { scheduleId } = await builder.cron('0 0 * * *').between(fromDate, toDate).run()
const schedule = await Schedule.find(scheduleId)
assert.deepEqual(schedule!.from, fromDate)
assert.deepEqual(schedule!.to, toDate)
})
test('should set run limit', async ({ assert }) => {
const builder = new ScheduleBuilder('LimitedJob', {})
const { scheduleId } = await builder.every('1h').limit(100).run()
const schedule = await Schedule.find(scheduleId)
assert.equal(schedule!.limit, 100)
})
test('should calculate nextRunAt on creation', async ({ assert }) => {
const builder = new ScheduleBuilder('SyncJob', {})
const { scheduleId } = await builder.every('5m').run()
const schedule = await Schedule.find(scheduleId)
assert.isNotNull(schedule!.nextRunAt)
// nextRunAt should be approximately 5 minutes from now
const expectedNextRun = Date.now() + 5 * 60 * 1000
const actualNextRun = schedule!.nextRunAt!.getTime()
// Allow 1 second tolerance
assert.isTrue(Math.abs(actualNextRun - expectedNextRun) < 1000)
})
test('should calculate nextRunAt from cron expression', async ({ assert }) => {
const builder = new ScheduleBuilder('CronJob', {})
const { scheduleId } = await builder.cron('0 0 * * *').run()
const schedule = await Schedule.find(scheduleId)
assert.isNotNull(schedule!.nextRunAt)
// nextRunAt should be in the future
assert.isTrue(schedule!.nextRunAt!.getTime() > Date.now())
})
test('should throw when neither cron nor every is set', async ({ assert }) => {
assert.plan(1)
const builder = new ScheduleBuilder('InvalidJob', {})
try {
await builder.run()
} catch (error) {
assert.instanceOf(error, errors.E_INVALID_SCHEDULE_CONFIG)
}
})
test('should throw when both cron and every are set', async ({ assert }) => {
assert.plan(1)
const builder = new ScheduleBuilder('InvalidJob', {})
try {
await builder.cron('0 0 * * *').every('5m').run()
} catch (error) {
assert.instanceOf(error, errors.E_INVALID_SCHEDULE_CONFIG)
}
})
test('should throw for invalid cron expression', async ({ assert }) => {
assert.plan(1)
const builder = new ScheduleBuilder('InvalidJob', {})
try {
await builder.cron('invalid cron').run()
} catch (error) {
assert.instanceOf(error, errors.E_INVALID_CRON_EXPRESSION)
}
})
test('should be thenable for auto-run', async ({ assert }) => {
const builder = new ScheduleBuilder('SyncJob', { source: 'api' })
// Using await directly on builder chain
const { scheduleId } = await builder.every('5m')
assert.isString(scheduleId)
})
test('should respect from() for nextRunAt calculation', async ({ assert }) => {
const futureDate = new Date(Date.now() + 24 * 60 * 60 * 1000) // tomorrow
const builder = new ScheduleBuilder('FutureJob', {})
const { scheduleId } = await builder.every('1h').from(futureDate).run()
const schedule = await Schedule.find(scheduleId)
// nextRunAt should be at or after from date
assert.isTrue(schedule!.nextRunAt!.getTime() >= futureDate.getTime())
})
})
test.group('Schedule', (group) => {
let sharedAdapter: ReturnType<ReturnType<typeof memory>>
group.each.setup(async () => {
sharedAdapter = memory()()
await QueueManager.init({
default: 'memory',
adapters: { memory: () => sharedAdapter },
})
return () => QueueManager.destroy()
})
test('Schedule.find() should return null for non-existent schedule', async ({ assert }) => {
const schedule = await Schedule.find('non-existent')
assert.isNull(schedule)
})
test('Schedule.find() should return schedule data', async ({ assert }) => {
const builder = new ScheduleBuilder('TestJob', { data: 'test' })
const { scheduleId } = await builder.id('test-schedule').every('5m').run()
const schedule = await Schedule.find(scheduleId)
assert.isNotNull(schedule)
assert.instanceOf(schedule, Schedule)
assert.equal(schedule!.id, 'test-schedule')
assert.equal(schedule!.name, 'TestJob')
assert.deepEqual(schedule!.payload, { data: 'test' })
})
test('Schedule.list() should return all schedules', async ({ assert }) => {
await new ScheduleBuilder('Job1', {}).id('schedule-1').every('5m').run()
await new ScheduleBuilder('Job2', {}).id('schedule-2').every('10m').run()
await new ScheduleBuilder('Job3', {}).id('schedule-3').cron('0 0 * * *').run()
const schedules = await Schedule.list()
assert.lengthOf(schedules, 3)
assert.isTrue(schedules.every((s) => s instanceof Schedule))
})
test('Schedule.list() should filter by status', async ({ assert }) => {
await new ScheduleBuilder('Job1', {}).id('active-schedule').every('5m').run()
const pausedSchedule = await Schedule.find('active-schedule')
await pausedSchedule!.pause()
await new ScheduleBuilder('Job2', {}).id('still-active').every('10m').run()
const activeSchedules = await Schedule.list({ status: 'active' })
const pausedSchedules = await Schedule.list({ status: 'paused' })
assert.lengthOf(activeSchedules, 1)
assert.equal(activeSchedules[0].id, 'still-active')
assert.lengthOf(pausedSchedules, 1)
assert.equal(pausedSchedules[0].id, 'active-schedule')
})
test('schedule.pause() should set status to paused', async ({ assert }) => {
await new ScheduleBuilder('TestJob', {}).id('pausable').every('5m').run()
const schedule = await Schedule.find('pausable')
await schedule!.pause()
const updated = await Schedule.find('pausable')
assert.equal(updated!.status, 'paused')
})
test('schedule.resume() should set status to active', async ({ assert }) => {
await new ScheduleBuilder('TestJob', {}).id('resumable').every('5m').run()
const schedule = await Schedule.find('resumable')
await schedule!.pause()
await schedule!.resume()
const updated = await Schedule.find('resumable')
assert.equal(updated!.status, 'active')
})
test('schedule.delete() should remove the schedule', async ({ assert }) => {
await new ScheduleBuilder('TestJob', {}).id('deletable').every('5m').run()
const schedule = await Schedule.find('deletable')
await schedule!.delete()
const deleted = await Schedule.find('deletable')
assert.isNull(deleted)
})
test('schedule.trigger() should dispatch job immediately', async ({ assert }) => {
await new ScheduleBuilder('TriggerJob', { immediate: true }).id('triggerable').every('1h').run()
const schedule = await Schedule.find('triggerable')
await schedule!.trigger()
// Job should be in the queue
const job = await sharedAdapter.pop()
assert.isNotNull(job)
assert.equal(job!.name, 'TriggerJob')
assert.deepEqual(job!.payload, { immediate: true })
})
test('schedule.trigger() should update lastRunAt and runCount', async ({ assert }) => {
await new ScheduleBuilder('TriggerJob', {}).id('trigger-updates').every('1h').run()
const schedule = await Schedule.find('trigger-updates')
const beforeRunCount = schedule!.runCount
await schedule!.trigger()
const updated = await Schedule.find('trigger-updates')
assert.equal(updated!.runCount, beforeRunCount + 1)
assert.isNotNull(updated!.lastRunAt)
})
test('schedule.trigger() should not run if limit is reached', async ({ assert }) => {
await new ScheduleBuilder('LimitedJob', {}).id('limited').every('1h').limit(1).run()
const schedule = await Schedule.find('limited')
await schedule!.trigger() // First run, should work
const updatedSchedule = await Schedule.find('limited')
await updatedSchedule!.trigger() // Second run, should be skipped
// Only one job should be in the queue
const job1 = await sharedAdapter.pop()
const job2 = await sharedAdapter.pop()
assert.isNotNull(job1)
assert.isNull(job2)
})
test('schedule.trigger(payload) should dispatch job with custom payload', async ({ assert }) => {
await new ScheduleBuilder('TriggerJob', { immediate: true, custom: false })
.id('triggerable')
.every('1h')
.run()
const schedule = await Schedule.find('triggerable')
await schedule!.trigger({ immediate: true, custom: true })
// Job should be in the queue
const job = await sharedAdapter.pop()
assert.isNotNull(job)
assert.equal(job!.name, 'TriggerJob')
assert.deepEqual(job!.payload, { immediate: true, custom: true })
})
test('schedule properties should reflect data', async ({ assert }) => {
const fromDate = new Date('2025-01-01')
const toDate = new Date('2025-12-31')
await new ScheduleBuilder('FullJob', { key: 'value' })
.id('full-schedule')
.cron('0 9 * * 1-5')
.timezone('America/New_York')
.between(fromDate, toDate)
.limit(50)
.run()
const schedule = await Schedule.find('full-schedule')
assert.equal(schedule!.id, 'full-schedule')
assert.equal(schedule!.name, 'FullJob')
assert.deepEqual(schedule!.payload, { key: 'value' })
assert.equal(schedule!.cronExpression, '0 9 * * 1-5')
assert.isNull(schedule!.everyMs)
assert.equal(schedule!.timezone, 'America/New_York')
assert.deepEqual(schedule!.from, fromDate)
assert.deepEqual(schedule!.to, toDate)
assert.equal(schedule!.limit, 50)
assert.equal(schedule!.runCount, 0)
assert.equal(schedule!.status, 'active')
assert.isNotNull(schedule!.createdAt)
})
})
test.group('Job.schedule()', (group) => {
class TestScheduleJob extends Job<{ value: string }> {
async execute() {}
}
group.each.setup(async () => {
const sharedAdapter = memory()()
// Register the job
Locator.register(TestScheduleJob.name, TestScheduleJob)
await QueueManager.init({
default: 'memory',
adapters: { memory: () => sharedAdapter },
})
return () => {
Locator.clear()
return QueueManager.destroy()
}
})
test('Job.schedule() should return a ScheduleBuilder', async ({ assert }) => {
const builder = TestScheduleJob.schedule({ value: 'test' })
assert.instanceOf(builder, ScheduleBuilder)
})
test('Job.schedule() should create a schedule with job name', async ({ assert }) => {
const { scheduleId } = await TestScheduleJob.schedule({ value: 'hello' })
.id('test-job-schedule')
.every('10m')
.run()
const schedule = await Schedule.find(scheduleId)
assert.isNotNull(schedule)
assert.equal(schedule!.name, 'TestScheduleJob')
assert.deepEqual(schedule!.payload, { value: 'hello' })
})
test('Job.schedule() should work with cron expression', async ({ assert }) => {
const { scheduleId } = await TestScheduleJob.schedule({ value: 'cron-test' })
.cron('0 */2 * * *')
.timezone('Europe/Paris')
.run()
const schedule = await Schedule.find(scheduleId)
assert.isNotNull(schedule)
assert.equal(schedule!.cronExpression, '0 */2 * * *')
assert.equal(schedule!.timezone, 'Europe/Paris')
})
test('Job.schedule() should be thenable', async ({ assert }) => {
const { scheduleId } = await TestScheduleJob.schedule({ value: 'thenable' }).every('1h')
assert.isString(scheduleId)
const schedule = await Schedule.find(scheduleId)
assert.equal(schedule!.everyMs, 60 * 60 * 1000)
})
})
test.group('claimDueSchedule', (group) => {
let sharedAdapter: ReturnType<ReturnType<typeof memory>>
group.each.setup(async () => {
sharedAdapter = memory()()
await QueueManager.init({
default: 'memory',
adapters: { memory: () => sharedAdapter },
})
return () => QueueManager.destroy()
})
test('should return null when no schedules are due', async ({ assert }) => {
// Create a schedule with nextRunAt in the future
await new ScheduleBuilder('FutureJob', {}).id('future').every('1h').run()
const claimed = await sharedAdapter.claimDueSchedule()
assert.isNull(claimed)
})
test('should claim a due schedule', async ({ assert }) => {
await new ScheduleBuilder('DueJob', { key: 'value' }).id('due-schedule').every('5m').run()
// Manually set nextRunAt to the past to make it due
await sharedAdapter.updateSchedule('due-schedule', {
nextRunAt: new Date(Date.now() - 1000),
})
const claimed = await sharedAdapter.claimDueSchedule()
assert.isNotNull(claimed)
assert.equal(claimed!.id, 'due-schedule')
assert.equal(claimed!.name, 'DueJob')
assert.deepEqual(claimed!.payload, { key: 'value' })
})
test('should update nextRunAt after claiming', async ({ assert }) => {
await new ScheduleBuilder('IntervalJob', {}).id('interval-schedule').every('10m').run()
// Make it due
const pastDate = new Date(Date.now() - 1000)
await sharedAdapter.updateSchedule('interval-schedule', { nextRunAt: pastDate })
const beforeClaim = await sharedAdapter.getSchedule('interval-schedule')
assert.deepEqual(beforeClaim!.nextRunAt, pastDate)
await sharedAdapter.claimDueSchedule()
const afterClaim = await sharedAdapter.getSchedule('interval-schedule')
// nextRunAt should be ~10 minutes in the future
assert.isNotNull(afterClaim!.nextRunAt)
assert.isTrue(afterClaim!.nextRunAt!.getTime() > Date.now())
})
test('should increment runCount after claiming', async ({ assert }) => {
await new ScheduleBuilder('CountJob', {}).id('count-schedule').every('5m').run()
await sharedAdapter.updateSchedule('count-schedule', {
nextRunAt: new Date(Date.now() - 1000),
})
const before = await sharedAdapter.getSchedule('count-schedule')
assert.equal(before!.runCount, 0)
await sharedAdapter.claimDueSchedule()
const after = await sharedAdapter.getSchedule('count-schedule')
assert.equal(after!.runCount, 1)
})
test('should set lastRunAt after claiming', async ({ assert }) => {
await new ScheduleBuilder('LastRunJob', {}).id('lastrun-schedule').every('5m').run()
await sharedAdapter.updateSchedule('lastrun-schedule', {
nextRunAt: new Date(Date.now() - 1000),
})
const before = await sharedAdapter.getSchedule('lastrun-schedule')
assert.isNull(before!.lastRunAt)
const now = Date.now()
await sharedAdapter.claimDueSchedule()
const after = await sharedAdapter.getSchedule('lastrun-schedule')
assert.isNotNull(after!.lastRunAt)
// Should be approximately now
assert.isTrue(Math.abs(after!.lastRunAt!.getTime() - now) < 1000)
})
test('should not claim paused schedules', async ({ assert }) => {
await new ScheduleBuilder('PausedJob', {}).id('paused-schedule').every('5m').run()
await sharedAdapter.updateSchedule('paused-schedule', {
nextRunAt: new Date(Date.now() - 1000),
status: 'paused',
})
const claimed = await sharedAdapter.claimDueSchedule()
assert.isNull(claimed)
})
test('should not claim schedule when limit is reached', async ({ assert }) => {
await new ScheduleBuilder('LimitedJob', {}).id('limited-schedule').every('5m').limit(3).run()
await sharedAdapter.updateSchedule('limited-schedule', {
nextRunAt: new Date(Date.now() - 1000),
runCount: 3, // Already at limit
})
const claimed = await sharedAdapter.claimDueSchedule()
assert.isNull(claimed)
})
test('should set nextRunAt to null when limit will be reached', async ({ assert }) => {
await new ScheduleBuilder('LastRunLimitJob', {}).id('lastrun-limit').every('5m').limit(1).run()
await sharedAdapter.updateSchedule('lastrun-limit', {
nextRunAt: new Date(Date.now() - 1000),
runCount: 0,
})
await sharedAdapter.claimDueSchedule()
const after = await sharedAdapter.getSchedule('lastrun-limit')
assert.isNull(after!.nextRunAt) // No more runs
assert.equal(after!.runCount, 1)
})
test('should not claim schedule past end date (to)', async ({ assert }) => {
const pastDate = new Date(Date.now() - 24 * 60 * 60 * 1000) // yesterday
await new ScheduleBuilder('ExpiredJob', {})
.id('expired-schedule')
.every('5m')
.to(pastDate)
.run()
await sharedAdapter.updateSchedule('expired-schedule', {
nextRunAt: new Date(Date.now() - 1000),
})
const claimed = await sharedAdapter.claimDueSchedule()
assert.isNull(claimed)
})
test('should only claim one schedule at a time', async ({ assert }) => {
// Create multiple due schedules
await new ScheduleBuilder('Job1', {}).id('schedule-1').every('5m').run()
await new ScheduleBuilder('Job2', {}).id('schedule-2').every('5m').run()
await new ScheduleBuilder('Job3', {}).id('schedule-3').every('5m').run()
const pastDate = new Date(Date.now() - 1000)
await sharedAdapter.updateSchedule('schedule-1', { nextRunAt: pastDate })
await sharedAdapter.updateSchedule('schedule-2', { nextRunAt: pastDate })
await sharedAdapter.updateSchedule('schedule-3', { nextRunAt: pastDate })
const claimed1 = await sharedAdapter.claimDueSchedule()
const claimed2 = await sharedAdapter.claimDueSchedule()
const claimed3 = await sharedAdapter.claimDueSchedule()
const claimed4 = await sharedAdapter.claimDueSchedule()
assert.isNotNull(claimed1)
assert.isNotNull(claimed2)
assert.isNotNull(claimed3)
assert.isNull(claimed4) // No more due schedules
// All should be different
const ids = [claimed1!.id, claimed2!.id, claimed3!.id]
assert.lengthOf(new Set(ids), 3)
})
})