@@ -7,8 +7,11 @@ import { MockJobContext, setupDefaultJobEnvironment } from '../../../../__mocks_
7
7
import { ProcessedShowStyleCompound } from '../../../../jobs'
8
8
import { ReadonlyDeep } from 'type-fest'
9
9
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
10
- import { loadPlayoutModelPreInit } from '../LoadPlayoutModel'
10
+ import { createPlayoutModelFromIngestModel , loadPlayoutModelPreInit } from '../LoadPlayoutModel'
11
11
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'
12
15
13
16
describe ( 'LoadPlayoutModel' , ( ) => {
14
17
let context : MockJobContext
@@ -94,4 +97,63 @@ describe('LoadPlayoutModel', () => {
94
97
} )
95
98
} )
96
99
} )
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
+ } )
97
159
} )
0 commit comments