Skip to content

Commit 32acf63

Browse files
committed
fix(LoadPlayoutModel): rundowns are unsorted in createPlayoutModelFromIngestModel
1 parent ea7cece commit 32acf63

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

packages/corelib/src/playout/playlist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export function sortRundownIDsInPlaylist(
9393

9494
export function sortRundownsWithinPlaylist(
9595
sortedPossibleIds: ReadonlyDeep<RundownId[]>,
96-
unsortedRundowns: DBRundown[]
97-
): DBRundown[] {
96+
unsortedRundowns: ReadonlyDeep<DBRundown[]>
97+
): ReadonlyDeep<DBRundown[]> {
9898
return unsortedRundowns.slice().sort((a, b) => {
9999
const indexA = sortedPossibleIds.indexOf(a._id)
100100
const indexB = sortedPossibleIds.indexOf(b._id)

packages/job-worker/src/playout/model/PlayoutModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface PlayoutModelPreInit {
5555
*/
5656
readonly playlist: ReadonlyDeep<DBRundownPlaylist>
5757
/**
58-
* The unwrapped Rundowns in this RundownPlaylist
58+
* The unwrapped Rundowns in this RundownPlaylist, sorted in order specified by RundownPlaylist
5959
*/
6060
readonly rundowns: ReadonlyDeep<DBRundown[]>
6161

packages/job-worker/src/playout/model/implementation/LoadPlayoutModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function createPlayoutModelFromIngestModel(
9090

9191
const [partInstances, rundownsWithContent, timeline] = await Promise.all([
9292
loadPartInstances(context, loadedPlaylist, rundownIds),
93-
loadRundowns(context, ingestModel, rundowns),
93+
loadRundowns(context, ingestModel, sortRundownsWithinPlaylist(playlist.rundownIdsInOrder, rundowns)),
9494
loadTimeline(context),
9595
])
9696

packages/job-worker/src/playout/model/implementation/__tests__/LoadPlayoutModel.spec.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import { MockJobContext, setupDefaultJobEnvironment } from '../../../../__mocks_
77
import { ProcessedShowStyleCompound } from '../../../../jobs'
88
import { ReadonlyDeep } from 'type-fest'
99
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
10-
import { loadPlayoutModelPreInit } from '../LoadPlayoutModel'
10+
import { createPlayoutModelFromIngestModel, loadPlayoutModelPreInit } from '../LoadPlayoutModel'
1111
import { runWithPlaylistLock } from '../../../../playout/lock'
12+
import { loadIngestModelFromRundown } from '../../../../ingest/model/implementation/LoadIngestModel'
13+
import { runWithRundownLock } from '../../../../ingest/lock'
14+
import { IngestModelReadonly } from '../../../../ingest/model/IngestModel'
1215

1316
describe('LoadPlayoutModel', () => {
1417
let context: MockJobContext
@@ -94,4 +97,63 @@ describe('LoadPlayoutModel', () => {
9497
})
9598
})
9699
})
100+
101+
describe('createPlayoutModelFromIngestModel', () => {
102+
afterEach(async () =>
103+
Promise.all([
104+
context.mockCollections.RundownBaselineAdLibPieces.remove({}),
105+
context.mockCollections.RundownBaselineAdLibActions.remove({}),
106+
context.mockCollections.RundownBaselineObjects.remove({}),
107+
context.mockCollections.AdLibActions.remove({}),
108+
context.mockCollections.AdLibPieces.remove({}),
109+
context.mockCollections.Pieces.remove({}),
110+
context.mockCollections.Parts.remove({}),
111+
context.mockCollections.Segments.remove({}),
112+
context.mockCollections.Rundowns.remove({}),
113+
context.mockCollections.RundownPlaylists.remove({}),
114+
])
115+
)
116+
117+
test('Rundowns are in order specified in RundownPlaylist', async () => {
118+
// Set up a playlist:
119+
const { rundownId: rundownId00, playlistId: playlistId0 } = await setupDefaultRundownPlaylist(
120+
context,
121+
showStyleCompound,
122+
protectString('rundown00')
123+
)
124+
const rundownId01 = protectString('rundown01')
125+
await setupDefaultRundown(context, showStyleCompound, playlistId0, rundownId01)
126+
const rundownId02 = protectString('rundown02')
127+
await setupDefaultRundown(context, showStyleCompound, playlistId0, rundownId02)
128+
129+
const rundownIdsInOrder = [rundownId01, rundownId02, rundownId00]
130+
131+
await context.mockCollections.RundownPlaylists.update(playlistId0, {
132+
rundownIdsInOrder,
133+
})
134+
135+
const playlist0 = await context.mockCollections.RundownPlaylists.findOne(playlistId0)
136+
expect(playlist0).toBeTruthy()
137+
138+
if (!playlist0) throw new Error(`Playlist "${playlistId0}" not found!`)
139+
140+
let ingestModel: IngestModelReadonly | undefined
141+
142+
await runWithRundownLock(context, rundownId01, async (rundown, lock) => {
143+
if (!rundown) throw new Error(`Rundown "${rundownId01}" not found!`)
144+
145+
ingestModel = await loadIngestModelFromRundown(context, lock, rundown)
146+
})
147+
148+
await runWithPlaylistLock(context, playlistId0, async (lock) => {
149+
if (!ingestModel) throw new Error('Ingest model could not be created!')
150+
151+
const rundowns = await context.mockCollections.Rundowns.findFetch({})
152+
153+
const model = await createPlayoutModelFromIngestModel(context, lock, playlist0, rundowns, ingestModel)
154+
155+
expect(model.rundowns.map((r) => r.rundown._id)).toMatchObject([rundownId01, rundownId02, rundownId00])
156+
})
157+
})
158+
})
97159
})

0 commit comments

Comments
 (0)