@@ -1285,6 +1285,53 @@ describe('Test blueprint api context', () => {
12851285 } )
12861286 } )
12871287
1288+ test ( 'good with explicit insert before part externalId' , async ( ) => {
1289+ const { jobContext, playlistId, rundownId } = await setupMyDefaultRundown ( )
1290+
1291+ const partInstance = ( await jobContext . mockCollections . PartInstances . findOne ( {
1292+ rundownId,
1293+ 'part.externalId' : 'MOCK_PART_0_0' ,
1294+ } ) ) as DBPartInstance
1295+ expect ( partInstance ) . toBeTruthy ( )
1296+ await setPartInstances ( jobContext , playlistId , partInstance , undefined )
1297+
1298+ const targetPart = await jobContext . mockCollections . Parts . findOne ( {
1299+ externalId : 'MOCK_PART_1_1' ,
1300+ rundownId,
1301+ } )
1302+ expect ( targetPart ) . toBeTruthy ( )
1303+
1304+ await wrapWithPlayoutModel ( jobContext , playlistId , async ( playoutModel ) => {
1305+ const { service } = await getTestee ( jobContext , playoutModel )
1306+
1307+ const newPiece : IBlueprintPiece = {
1308+ name : 'test piece' ,
1309+ sourceLayerId : 'sl1' ,
1310+ outputLayerId : 'o1' ,
1311+ externalId : '-' ,
1312+ enable : { start : 0 } ,
1313+ lifespan : PieceLifespan . OutOnRundownEnd ,
1314+ content : {
1315+ timelineObjects : [ ] ,
1316+ } ,
1317+ }
1318+ const newPart : IBlueprintPart = {
1319+ externalId : 'nope' ,
1320+ title : 'something' ,
1321+ }
1322+
1323+ postProcessPiecesMock . mockImplementationOnce ( postProcessPiecesOrig )
1324+ insertQueuedPartWithPiecesMock . mockImplementationOnce ( insertQueuedPartWithPiecesOrig )
1325+ await service . queuePart ( newPart , [ newPiece ] , { targetPartId : 'MOCK_PART_1_1' } )
1326+
1327+ const newPartInstance = playoutModel . getPartInstance (
1328+ playoutModel . playlist . nextPartInfo ! . partInstanceId
1329+ ) !
1330+ expect ( newPartInstance . partInstance . segmentId ) . toEqual ( targetPart ! . segmentId )
1331+ expect ( newPartInstance . partInstance . part . _rank ) . toBeLessThan ( targetPart ! . _rank )
1332+ } )
1333+ } )
1334+
12881335 test ( 'unknown insert before part id' , async ( ) => {
12891336 const { jobContext, playlistId, rundownId } = await setupMyDefaultRundown ( )
12901337
@@ -1578,6 +1625,52 @@ describe('Test blueprint api context', () => {
15781625 } )
15791626 } )
15801627
1628+ test ( 'prepareQueueablePartAndPieces converts targetPartId from externalId to _id' , async ( ) => {
1629+ const { jobContext, playlistId, rundownId } = await setupMyDefaultRundown ( )
1630+
1631+ const partInstance = ( await jobContext . mockCollections . PartInstances . findOne ( {
1632+ rundownId,
1633+ 'part.externalId' : 'MOCK_PART_0_0' ,
1634+ } ) ) as DBPartInstance
1635+ expect ( partInstance ) . toBeTruthy ( )
1636+ await setPartInstances ( jobContext , playlistId , partInstance , undefined )
1637+
1638+ const targetPart = await jobContext . mockCollections . Parts . findOne ( {
1639+ externalId : 'MOCK_PART_1_1' ,
1640+ rundownId,
1641+ } )
1642+ expect ( targetPart ) . toBeTruthy ( )
1643+
1644+ await wrapWithPlayoutModel ( jobContext , playlistId , async ( playoutModel ) => {
1645+ const { service } = await getTestee ( jobContext , playoutModel )
1646+
1647+ const currentPartInstance = playoutModel . currentPartInstance !
1648+ postProcessPiecesMock . mockImplementationOnce ( postProcessPiecesOrig )
1649+
1650+ const queueable = service . prepareQueueablePartAndPieces (
1651+ { externalId : 'nope' , title : 'something' } ,
1652+ [
1653+ {
1654+ name : 'test piece' ,
1655+ sourceLayerId : 'sl1' ,
1656+ outputLayerId : 'o1' ,
1657+ externalId : '-' ,
1658+ enable : { start : 0 } ,
1659+ lifespan : PieceLifespan . OutOnRundownEnd ,
1660+ content : {
1661+ timelineObjects : [ ] ,
1662+ } ,
1663+ } ,
1664+ ] ,
1665+ currentPartInstance ,
1666+ { targetPartId : 'MOCK_PART_1_1' }
1667+ )
1668+
1669+ expect ( queueable . target ?. targetPartId ) . toEqual ( unprotectString ( targetPart ! . _id ) )
1670+ expect ( queueable . target ?. targetPartId ) . not . toEqual ( 'MOCK_PART_1_1' )
1671+ } )
1672+ } )
1673+
15811674 test ( 'good with explicit insert after part id' , async ( ) => {
15821675 const { jobContext, playlistId, rundownId } = await setupMyDefaultRundown ( )
15831676
0 commit comments