@@ -344,15 +344,15 @@ describe('ensureNextPartIsValid', () => {
344
344
} )
345
345
}
346
346
async function ensureNextPartIsValid ( ) {
347
- await runJobWithPlayoutCache ( context , { playlistId : rundownPlaylistId } , null , async ( cache ) =>
347
+ return runJobWithPlayoutCache ( context , { playlistId : rundownPlaylistId } , null , async ( cache ) =>
348
348
ensureNextPartIsValidRaw ( context , cache )
349
349
)
350
350
}
351
351
352
352
test ( 'Start with null' , async ( ) => {
353
353
await resetPartIds ( null , null )
354
354
355
- await ensureNextPartIsValid ( )
355
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
356
356
357
357
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
358
358
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -365,7 +365,7 @@ describe('ensureNextPartIsValid', () => {
365
365
test ( 'Missing next PartInstance' , async ( ) => {
366
366
await resetPartIds ( 'mock_part_instance3' , 'fake_part' )
367
367
368
- await ensureNextPartIsValid ( )
368
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
369
369
370
370
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
371
371
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -380,14 +380,14 @@ describe('ensureNextPartIsValid', () => {
380
380
test ( 'Missing current PartInstance with valid next' , async ( ) => {
381
381
await resetPartIds ( 'fake_part' , 'mock_part_instance4' )
382
382
383
- await ensureNextPartIsValid ( )
383
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
384
384
385
385
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 0 )
386
386
} )
387
387
test ( 'Missing current and next PartInstance' , async ( ) => {
388
388
await resetPartIds ( 'fake_part' , 'not_real_either' )
389
389
390
- await ensureNextPartIsValid ( )
390
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
391
391
392
392
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
393
393
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -400,21 +400,21 @@ describe('ensureNextPartIsValid', () => {
400
400
test ( 'Ensure correct PartInstance doesnt change' , async ( ) => {
401
401
await resetPartIds ( 'mock_part_instance3' , 'mock_part_instance4' )
402
402
403
- await ensureNextPartIsValid ( )
403
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
404
404
405
405
expect ( setNextPartMock ) . not . toHaveBeenCalled ( )
406
406
} )
407
407
test ( 'Ensure manual PartInstance doesnt change' , async ( ) => {
408
408
await resetPartIds ( 'mock_part_instance3' , 'mock_part_instance5' , true )
409
409
410
- await ensureNextPartIsValid ( )
410
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
411
411
412
412
expect ( setNextPartMock ) . not . toHaveBeenCalled ( )
413
413
} )
414
414
test ( 'Ensure non-manual PartInstance does change' , async ( ) => {
415
415
await resetPartIds ( 'mock_part_instance3' , 'mock_part_instance5' , false )
416
416
417
- await ensureNextPartIsValid ( )
417
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
418
418
419
419
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
420
420
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -427,7 +427,7 @@ describe('ensureNextPartIsValid', () => {
427
427
test ( 'Ensure manual but missing PartInstance does change' , async ( ) => {
428
428
await resetPartIds ( 'mock_part_instance3' , 'fake_part' , true )
429
429
430
- await ensureNextPartIsValid ( )
430
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
431
431
432
432
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
433
433
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -440,7 +440,7 @@ describe('ensureNextPartIsValid', () => {
440
440
test ( 'Ensure manual but floated PartInstance does change' , async ( ) => {
441
441
await resetPartIds ( 'mock_part_instance7' , 'mock_part_instance8' , true )
442
442
443
- await ensureNextPartIsValid ( )
443
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
444
444
445
445
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
446
446
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -453,7 +453,7 @@ describe('ensureNextPartIsValid', () => {
453
453
test ( 'Ensure floated PartInstance does change' , async ( ) => {
454
454
await resetPartIds ( 'mock_part_instance7' , 'mock_part_instance8' , false )
455
455
456
- await ensureNextPartIsValid ( )
456
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
457
457
458
458
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
459
459
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -490,7 +490,7 @@ describe('ensureNextPartIsValid', () => {
490
490
491
491
await resetPartIds ( null , instanceId , false )
492
492
493
- await ensureNextPartIsValid ( )
493
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
494
494
495
495
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
496
496
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -527,7 +527,7 @@ describe('ensureNextPartIsValid', () => {
527
527
528
528
await resetPartIds ( null , instanceId , true )
529
529
530
- await ensureNextPartIsValid ( )
530
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
531
531
532
532
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
533
533
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -568,7 +568,7 @@ describe('ensureNextPartIsValid', () => {
568
568
569
569
await resetPartIds ( 'mock_part_instance1' , instanceId , false )
570
570
571
- await ensureNextPartIsValid ( )
571
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
572
572
573
573
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 0 )
574
574
} )
@@ -601,7 +601,7 @@ describe('ensureNextPartIsValid', () => {
601
601
try {
602
602
// make sure it finds the part we expect
603
603
await resetPartIds ( 'mock_part_instance9' , null , false )
604
- await ensureNextPartIsValid ( )
604
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
605
605
606
606
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
607
607
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -619,7 +619,7 @@ describe('ensureNextPartIsValid', () => {
619
619
await context . mockCollections . Parts . remove ( part . _id )
620
620
621
621
// make sure the next part gets cleared
622
- await ensureNextPartIsValid ( )
622
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
623
623
624
624
expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
625
625
expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -634,4 +634,26 @@ describe('ensureNextPartIsValid', () => {
634
634
await context . mockCollections . Parts . remove ( part . _id )
635
635
}
636
636
} )
637
+
638
+ test ( 'Current part is last in rundown, next is missing' , async ( ) => {
639
+ await resetPartIds ( 'mock_part_instance9' , 'fake_part_instance' , false )
640
+
641
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
642
+
643
+ expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
644
+ expect ( setNextPartMock ) . toHaveBeenCalledWith (
645
+ expect . objectContaining ( { } ) ,
646
+ expect . objectContaining ( { PlaylistId : rundownPlaylistId } ) ,
647
+ null ,
648
+ false
649
+ )
650
+ } )
651
+
652
+ test ( 'Current part is last in rundown, no-op to update' , async ( ) => {
653
+ await resetPartIds ( 'mock_part_instance9' , null , false )
654
+
655
+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
656
+
657
+ expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 0 )
658
+ } )
637
659
} )
0 commit comments