@@ -344,15 +344,15 @@ describe('ensureNextPartIsValid', () => {
344344 } )
345345 }
346346 async function ensureNextPartIsValid ( ) {
347- await runJobWithPlayoutCache ( context , { playlistId : rundownPlaylistId } , null , async ( cache ) =>
347+ return runJobWithPlayoutCache ( context , { playlistId : rundownPlaylistId } , null , async ( cache ) =>
348348 ensureNextPartIsValidRaw ( context , cache )
349349 )
350350 }
351351
352352 test ( 'Start with null' , async ( ) => {
353353 await resetPartIds ( null , null )
354354
355- await ensureNextPartIsValid ( )
355+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
356356
357357 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
358358 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -365,7 +365,7 @@ describe('ensureNextPartIsValid', () => {
365365 test ( 'Missing next PartInstance' , async ( ) => {
366366 await resetPartIds ( 'mock_part_instance3' , 'fake_part' )
367367
368- await ensureNextPartIsValid ( )
368+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
369369
370370 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
371371 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -380,14 +380,14 @@ describe('ensureNextPartIsValid', () => {
380380 test ( 'Missing current PartInstance with valid next' , async ( ) => {
381381 await resetPartIds ( 'fake_part' , 'mock_part_instance4' )
382382
383- await ensureNextPartIsValid ( )
383+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
384384
385385 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 0 )
386386 } )
387387 test ( 'Missing current and next PartInstance' , async ( ) => {
388388 await resetPartIds ( 'fake_part' , 'not_real_either' )
389389
390- await ensureNextPartIsValid ( )
390+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
391391
392392 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
393393 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -400,21 +400,21 @@ describe('ensureNextPartIsValid', () => {
400400 test ( 'Ensure correct PartInstance doesnt change' , async ( ) => {
401401 await resetPartIds ( 'mock_part_instance3' , 'mock_part_instance4' )
402402
403- await ensureNextPartIsValid ( )
403+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
404404
405405 expect ( setNextPartMock ) . not . toHaveBeenCalled ( )
406406 } )
407407 test ( 'Ensure manual PartInstance doesnt change' , async ( ) => {
408408 await resetPartIds ( 'mock_part_instance3' , 'mock_part_instance5' , true )
409409
410- await ensureNextPartIsValid ( )
410+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
411411
412412 expect ( setNextPartMock ) . not . toHaveBeenCalled ( )
413413 } )
414414 test ( 'Ensure non-manual PartInstance does change' , async ( ) => {
415415 await resetPartIds ( 'mock_part_instance3' , 'mock_part_instance5' , false )
416416
417- await ensureNextPartIsValid ( )
417+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
418418
419419 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
420420 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -427,7 +427,7 @@ describe('ensureNextPartIsValid', () => {
427427 test ( 'Ensure manual but missing PartInstance does change' , async ( ) => {
428428 await resetPartIds ( 'mock_part_instance3' , 'fake_part' , true )
429429
430- await ensureNextPartIsValid ( )
430+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
431431
432432 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
433433 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -440,7 +440,7 @@ describe('ensureNextPartIsValid', () => {
440440 test ( 'Ensure manual but floated PartInstance does change' , async ( ) => {
441441 await resetPartIds ( 'mock_part_instance7' , 'mock_part_instance8' , true )
442442
443- await ensureNextPartIsValid ( )
443+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
444444
445445 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
446446 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -453,7 +453,7 @@ describe('ensureNextPartIsValid', () => {
453453 test ( 'Ensure floated PartInstance does change' , async ( ) => {
454454 await resetPartIds ( 'mock_part_instance7' , 'mock_part_instance8' , false )
455455
456- await ensureNextPartIsValid ( )
456+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
457457
458458 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
459459 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -490,7 +490,7 @@ describe('ensureNextPartIsValid', () => {
490490
491491 await resetPartIds ( null , instanceId , false )
492492
493- await ensureNextPartIsValid ( )
493+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
494494
495495 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
496496 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -527,7 +527,7 @@ describe('ensureNextPartIsValid', () => {
527527
528528 await resetPartIds ( null , instanceId , true )
529529
530- await ensureNextPartIsValid ( )
530+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
531531
532532 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
533533 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -568,7 +568,7 @@ describe('ensureNextPartIsValid', () => {
568568
569569 await resetPartIds ( 'mock_part_instance1' , instanceId , false )
570570
571- await ensureNextPartIsValid ( )
571+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeFalsy ( )
572572
573573 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 0 )
574574 } )
@@ -601,7 +601,7 @@ describe('ensureNextPartIsValid', () => {
601601 try {
602602 // make sure it finds the part we expect
603603 await resetPartIds ( 'mock_part_instance9' , null , false )
604- await ensureNextPartIsValid ( )
604+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
605605
606606 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
607607 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -619,7 +619,7 @@ describe('ensureNextPartIsValid', () => {
619619 await context . mockCollections . Parts . remove ( part . _id )
620620
621621 // make sure the next part gets cleared
622- await ensureNextPartIsValid ( )
622+ await expect ( ensureNextPartIsValid ( ) ) . resolves . toBeTruthy ( )
623623
624624 expect ( setNextPartMock ) . toHaveBeenCalledTimes ( 1 )
625625 expect ( setNextPartMock ) . toHaveBeenCalledWith (
@@ -634,4 +634,26 @@ describe('ensureNextPartIsValid', () => {
634634 await context . mockCollections . Parts . remove ( part . _id )
635635 }
636636 } )
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+ } )
637659} )
0 commit comments