Skip to content

Commit 902e7ff

Browse files
committed
feat: allow adlib-actions to remove pieces from the current partInstance
1 parent 1b31e45 commit 902e7ff

File tree

10 files changed

+54
-11
lines changed

10 files changed

+54
-11
lines changed

packages/blueprints-integration/src/context/onSetAsNextContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export interface IOnSetAsNextContext extends IShowStyleUserContext, IEventContex
6767
/**
6868
* Destructive actions
6969
*/
70-
/** Remove piecesInstances by id. Returns ids of piecesInstances that were removed. Note: For now we only allow removing from the next, but this might change to include current if there is justification */
71-
removePieceInstances(part: 'next', pieceInstanceIds: string[]): Promise<string[]>
70+
/** Remove piecesInstances by id. Returns ids of piecesInstances that were removed. */
71+
removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]>
7272

7373
/**
7474
* Move the next part through the rundown. Can move by either a number of parts, or segments in either direction.

packages/blueprints-integration/src/context/partsAndPieceActionContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ export interface IPartAndPieceActionContext {
6868
stopPiecesOnLayers(sourceLayerIds: string[], timeOffset?: number): Promise<string[]>
6969
/** Stop piecesInstances by id. Returns ids of piecesInstances that were removed */
7070
stopPieceInstances(pieceInstanceIds: string[], timeOffset?: number): Promise<string[]>
71-
/** Remove piecesInstances by id. Returns ids of piecesInstances that were removed. Note: For now we only allow removing from the next, but this might change to include current if there is justification */
72-
removePieceInstances(part: 'next', pieceInstanceIds: string[]): Promise<string[]>
71+
/** Remove piecesInstances by id. Returns ids of piecesInstances that were removed. */
72+
removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]>
7373
}

packages/job-worker/src/blueprints/__tests__/context-OnSetAsNextContext.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ describe('Test blueprint api context', () => {
113113
await context.removePieceInstances('next', ['pieceInstanceId'])
114114
expect(mockActionService.removePieceInstances).toHaveBeenCalledTimes(1)
115115
expect(mockActionService.removePieceInstances).toHaveBeenCalledWith('next', ['pieceInstanceId'])
116+
117+
await context.removePieceInstances('current', ['pieceInstanceId'])
118+
expect(mockActionService.removePieceInstances).toHaveBeenCalledTimes(2)
119+
expect(mockActionService.removePieceInstances).toHaveBeenCalledWith('current', ['pieceInstanceId'])
116120
})
117121

118122
test('updatePartInstance', async () => {

packages/job-worker/src/blueprints/__tests__/context-OnTakeContext.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ describe('Test blueprint api context', () => {
129129
await context.removePieceInstances('next', ['pieceInstanceId'])
130130
expect(mockActionService.removePieceInstances).toHaveBeenCalledTimes(1)
131131
expect(mockActionService.removePieceInstances).toHaveBeenCalledWith('next', ['pieceInstanceId'])
132+
133+
await context.removePieceInstances('current', ['pieceInstanceId'])
134+
expect(mockActionService.removePieceInstances).toHaveBeenCalledTimes(2)
135+
expect(mockActionService.removePieceInstances).toHaveBeenCalledWith('current', ['pieceInstanceId'])
132136
})
133137

134138
test('updatePartInstance', async () => {

packages/job-worker/src/blueprints/__tests__/context-adlibActions.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ describe('Test blueprint api context', () => {
139139
await context.removePieceInstances('next', ['pieceInstanceId'])
140140
expect(mockActionService.removePieceInstances).toHaveBeenCalledTimes(1)
141141
expect(mockActionService.removePieceInstances).toHaveBeenCalledWith('next', ['pieceInstanceId'])
142+
143+
await context.removePieceInstances('current', ['pieceInstanceId'])
144+
expect(mockActionService.removePieceInstances).toHaveBeenCalledTimes(2)
145+
expect(mockActionService.removePieceInstances).toHaveBeenCalledWith('current', ['pieceInstanceId'])
142146
})
143147

144148
test('updatePartInstance', async () => {

packages/job-worker/src/blueprints/context/OnSetAsNextContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ export class OnSetAsNextContext
117117
return this.partAndPieceInstanceService.updatePartInstance(part, props)
118118
}
119119

120-
async removePieceInstances(_part: 'next', pieceInstanceIds: string[]): Promise<string[]> {
121-
return this.partAndPieceInstanceService.removePieceInstances('next', pieceInstanceIds)
120+
async removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]> {
121+
return this.partAndPieceInstanceService.removePieceInstances(part, pieceInstanceIds)
122122
}
123123

124124
async moveNextPart(partDelta: number, segmentDelta: number, ignoreQuickLoop?: boolean): Promise<boolean> {

packages/job-worker/src/blueprints/context/OnTakeContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class OnTakeContext extends ShowStyleUserContext implements IOnTakeContex
117117
async stopPieceInstances(pieceInstanceIds: string[], timeOffset?: number | undefined): Promise<string[]> {
118118
return this.partAndPieceInstanceService.stopPieceInstances(pieceInstanceIds, timeOffset)
119119
}
120-
async removePieceInstances(part: 'next', pieceInstanceIds: string[]): Promise<string[]> {
120+
async removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]> {
121121
return this.partAndPieceInstanceService.removePieceInstances(part, pieceInstanceIds)
122122
}
123123

packages/job-worker/src/blueprints/context/adlibActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class ActionExecutionContext extends ShowStyleUserContext implements IAct
183183
return this.partAndPieceInstanceService.stopPieceInstances(pieceInstanceIds, timeOffset)
184184
}
185185

186-
async removePieceInstances(part: 'next', pieceInstanceIds: string[]): Promise<string[]> {
186+
async removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]> {
187187
return this.partAndPieceInstanceService.removePieceInstances(part, pieceInstanceIds)
188188
}
189189

packages/job-worker/src/blueprints/context/services/PartAndPieceInstanceActionService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ export class PartAndPieceInstanceActionService {
450450
)
451451
}
452452

453-
async removePieceInstances(_part: 'next', pieceInstanceIds: string[]): Promise<string[]> {
454-
const partInstance = this._getPartInstance('next')
453+
async removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]> {
454+
const partInstance = this._getPartInstance(part)
455455
if (!partInstance) {
456456
throw new Error('Cannot remove pieceInstances when no selected partInstance')
457457
}

packages/job-worker/src/blueprints/context/services/__tests__/PartAndPieceInstanceActionService.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ describe('Test blueprint api context', () => {
16101610
})
16111611
})
16121612

1613-
test('good', async () => {
1613+
test('good - from next', async () => {
16141614
const { jobContext, playlistId, allPartInstances } = await setupMyDefaultRundown()
16151615

16161616
const partInstance = allPartInstances[0]
@@ -1638,6 +1638,37 @@ describe('Test blueprint api context', () => {
16381638
expect(service.nextPartState).toEqual(ActionPartChange.SAFE_CHANGE)
16391639
})
16401640
})
1641+
1642+
test('good - from current', async () => {
1643+
const { jobContext, playlistId, allPartInstances } = await setupMyDefaultRundown()
1644+
1645+
const partInstance = allPartInstances[0]
1646+
await setPartInstances(jobContext, playlistId, partInstance, undefined)
1647+
1648+
await wrapWithPlayoutModel(jobContext, playlistId, async (playoutModel) => {
1649+
const { service } = await getTestee(jobContext, playoutModel)
1650+
1651+
const beforePieceInstancesCounts = getPieceInstanceCounts(playoutModel)
1652+
expect(beforePieceInstancesCounts.previous).toEqual(0)
1653+
expect(beforePieceInstancesCounts.current).not.toEqual(0)
1654+
expect(beforePieceInstancesCounts.next).toEqual(0)
1655+
expect(beforePieceInstancesCounts.other).toEqual(0)
1656+
1657+
// Find the instance, and create its backing piece
1658+
const targetPieceInstance = playoutModel.currentPartInstance!.pieceInstances[0]
1659+
expect(targetPieceInstance).toBeTruthy()
1660+
1661+
await expect(
1662+
service.removePieceInstances('current', [
1663+
unprotectString(targetPieceInstance.pieceInstance._id),
1664+
])
1665+
).resolves.toEqual([unprotectString(targetPieceInstance.pieceInstance._id)])
1666+
1667+
// Ensure it was all removed
1668+
expect(playoutModel.findPieceInstance(targetPieceInstance.pieceInstance._id)).toBeFalsy()
1669+
expect(service.nextPartState).toEqual(ActionPartChange.SAFE_CHANGE)
1670+
})
1671+
})
16411672
})
16421673

16431674
describe('updatePartInstance', () => {

0 commit comments

Comments
 (0)