Skip to content

Commit 3c0d3d5

Browse files
committed
chore: add tests
1 parent 82ba095 commit 3c0d3d5

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

packages/corelib/src/playout/playlist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ export function sortRundownsWithinPlaylist(
101101
if (indexA === -1 && indexB === -1) {
102102
return a._id.toString().localeCompare(b._id.toString())
103103
} else if (indexA === -1) {
104-
return -1
105-
} else if (indexB === -1) {
106104
return 1
105+
} else if (indexB === -1) {
106+
return -1
107107
}
108108

109109
return indexA - indexB

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export async function loadPlayoutModelPreInit(
6161

6262
playlist: Playlist,
6363
rundowns: sortRundownsWithinPlaylist(Playlist.rundownIdsInOrder, Rundowns),
64+
// rundowns: Rundowns,
6465

6566
getRundown: (id: RundownId) => Rundowns.find((rd) => rd._id === id),
6667
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import {
2+
setupDefaultRundown,
3+
setupDefaultRundownPlaylist,
4+
setupMockShowStyleCompound,
5+
} from '../../../../__mocks__/presetCollections'
6+
import { MockJobContext, setupDefaultJobEnvironment } from '../../../../__mocks__/context'
7+
import { ProcessedShowStyleCompound } from '../../../../jobs'
8+
import { ReadonlyDeep } from 'type-fest'
9+
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
10+
import { loadPlayoutModelPreInit } from '../LoadPlayoutModel'
11+
import { runWithPlaylistLock } from '../../../../playout/lock'
12+
13+
describe('LoadPlayoutModel', () => {
14+
let context: MockJobContext
15+
let showStyleCompound: ReadonlyDeep<ProcessedShowStyleCompound>
16+
17+
beforeAll(async () => {
18+
context = setupDefaultJobEnvironment()
19+
20+
showStyleCompound = await setupMockShowStyleCompound(context)
21+
})
22+
23+
describe('loadPlayoutModelPreInit', () => {
24+
afterEach(async () =>
25+
Promise.all([
26+
context.mockCollections.RundownBaselineAdLibPieces.remove({}),
27+
context.mockCollections.RundownBaselineAdLibActions.remove({}),
28+
context.mockCollections.RundownBaselineObjects.remove({}),
29+
context.mockCollections.AdLibActions.remove({}),
30+
context.mockCollections.AdLibPieces.remove({}),
31+
context.mockCollections.Pieces.remove({}),
32+
context.mockCollections.Parts.remove({}),
33+
context.mockCollections.Segments.remove({}),
34+
context.mockCollections.Rundowns.remove({}),
35+
context.mockCollections.RundownPlaylists.remove({}),
36+
])
37+
)
38+
39+
test('Rundowns are in order specified in RundownPlaylist', async () => {
40+
// Set up a playlist:
41+
const { rundownId: rundownId00, playlistId: playlistId0 } = await setupDefaultRundownPlaylist(
42+
context,
43+
showStyleCompound,
44+
protectString('rundown00')
45+
)
46+
const rundownId01 = protectString('rundown01')
47+
await setupDefaultRundown(context, showStyleCompound, playlistId0, rundownId01)
48+
const rundownId02 = protectString('rundown02')
49+
await setupDefaultRundown(context, showStyleCompound, playlistId0, rundownId02)
50+
51+
const playlist0 = await context.mockCollections.RundownPlaylists.findOne(playlistId0)
52+
expect(playlist0).toBeTruthy()
53+
54+
if (!playlist0) throw new Error(`Playlist "${playlistId0}" not found!`)
55+
56+
const rundownIdsInOrder = [rundownId01, rundownId02, rundownId00]
57+
58+
await context.mockCollections.RundownPlaylists.update(playlistId0, {
59+
rundownIdsInOrder,
60+
})
61+
62+
await runWithPlaylistLock(context, playlistId0, async (lock) => {
63+
const model = await loadPlayoutModelPreInit(context, lock, playlist0)
64+
expect(model.rundowns.map((r) => r._id)).toMatchObject([rundownId01, rundownId02, rundownId00])
65+
})
66+
})
67+
68+
test('Rundowns not ordered in RundownPlaylist are at the end', async () => {
69+
// Set up a playlist:
70+
const { rundownId: rundownId00, playlistId: playlistId0 } = await setupDefaultRundownPlaylist(
71+
context,
72+
showStyleCompound,
73+
protectString('rundown00')
74+
)
75+
const rundownId01 = protectString('rundown01')
76+
await setupDefaultRundown(context, showStyleCompound, playlistId0, rundownId01)
77+
const rundownId02 = protectString('rundown02')
78+
await setupDefaultRundown(context, showStyleCompound, playlistId0, rundownId02)
79+
80+
const playlist0 = await context.mockCollections.RundownPlaylists.findOne(playlistId0)
81+
expect(playlist0).toBeTruthy()
82+
83+
if (!playlist0) throw new Error(`Playlist "${playlistId0}" not found!`)
84+
85+
const rundownIdsInOrder = [rundownId01]
86+
87+
await context.mockCollections.RundownPlaylists.update(playlistId0, {
88+
rundownIdsInOrder,
89+
})
90+
91+
await runWithPlaylistLock(context, playlistId0, async (lock) => {
92+
const model = await loadPlayoutModelPreInit(context, lock, playlist0)
93+
expect(model.rundowns.map((r) => r._id)).toMatchObject([rundownId01, rundownId00, rundownId02])
94+
})
95+
})
96+
})
97+
})

0 commit comments

Comments
 (0)