Skip to content

Commit ce24481

Browse files
committed
wip: skeleton for unit tests
1 parent 5eb61fc commit ce24481

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/* eslint-disable @typescript-eslint/unbound-method */
2+
import { setupDefaultJobEnvironment } from '../../__mocks__/context'
3+
import { setupMockShowStyleCompound } from '../../__mocks__/presetCollections'
4+
import { PartInstanceToSync, SyncChangesToPartInstancesWorker } from '../syncChangesToPartInstance'
5+
import { mock } from 'jest-mock-extended'
6+
import type { PlayoutModel } from '../../playout/model/PlayoutModel'
7+
import type { IngestModelReadonly } from '../model/IngestModel'
8+
import type { PlayoutRundownModel } from '../../playout/model/PlayoutRundownModel'
9+
import type { PlayoutPartInstanceModel } from '../../playout/model/PlayoutPartInstanceModel'
10+
import type { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
11+
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
12+
13+
jest.mock('../../playout/adlibTesting')
14+
import { validateAdlibTestingPartInstanceProperties } from '../../playout/adlibTesting'
15+
16+
const mockOptions = {
17+
fallbackMockImplementation: () => {
18+
throw new Error('not mocked')
19+
},
20+
funcPropSupport: true,
21+
}
22+
23+
function createMockPart(): DBPart {
24+
return {
25+
_id: protectString('mockPartId'),
26+
_rank: 1,
27+
externalId: 'mockPartExternalId',
28+
segmentId: protectString('mockSegmentId'),
29+
rundownId: protectString('mockRundownId'),
30+
title: 'mockPartTitle',
31+
expectedDurationWithTransition: undefined,
32+
userEditOperations: undefined,
33+
}
34+
}
35+
36+
describe('SyncChangesToPartInstancesWorker', () => {
37+
describe('findInstancesToSync', () => {
38+
function createMockPlayoutModel(): PlayoutModel {
39+
return mock<PlayoutModel>(
40+
{
41+
currentPartInstance: null,
42+
nextPartInstance: null,
43+
previousPartInstance: null,
44+
},
45+
mockOptions
46+
)
47+
}
48+
function createMockPlayoutRundownModel(): PlayoutRundownModel {
49+
return mock<PlayoutRundownModel>({}, mockOptions)
50+
}
51+
function createMockIngestModelReadonly(): IngestModelReadonly {
52+
return mock<IngestModelReadonly>({}, mockOptions)
53+
}
54+
55+
test('No partInstances', async () => {
56+
const context = setupDefaultJobEnvironment()
57+
const showStyleCompound = await setupMockShowStyleCompound(context)
58+
const blueprint = await context.getShowStyleBlueprint(showStyleCompound._id)
59+
60+
const playoutModel = createMockPlayoutModel()
61+
const ingestModel = createMockIngestModelReadonly()
62+
const rundownModel = createMockPlayoutRundownModel()
63+
64+
const worker = new SyncChangesToPartInstancesWorker(
65+
context,
66+
playoutModel,
67+
ingestModel,
68+
rundownModel,
69+
showStyleCompound,
70+
blueprint
71+
)
72+
expect(worker).toBeTruthy()
73+
74+
const instancesToSync = worker.findInstancesToSync()
75+
expect(instancesToSync).toHaveLength(0)
76+
})
77+
78+
// TODO - this needs a lot more fleshing out
79+
})
80+
81+
describe('syncChangesToPartInstance', () => {
82+
function createMockPlayoutModel(): PlayoutModel {
83+
return mock<PlayoutModel>(
84+
{
85+
currentPartInstance: null,
86+
nextPartInstance: null,
87+
previousPartInstance: null,
88+
89+
clearAllNotifications: jest.fn(),
90+
},
91+
mockOptions
92+
)
93+
}
94+
function createMockPlayoutRundownModel(): PlayoutRundownModel {
95+
return mock<PlayoutRundownModel>({}, mockOptions)
96+
}
97+
function createMockIngestModelReadonly(): IngestModelReadonly {
98+
return mock<IngestModelReadonly>(
99+
{
100+
findPart: jest.fn(() => undefined),
101+
getGlobalPieces: jest.fn(() => []),
102+
},
103+
mockOptions
104+
)
105+
}
106+
107+
function createMockPartInstance(): PlayoutPartInstanceModel {
108+
return mock<PlayoutPartInstanceModel>(
109+
{
110+
partInstance: {
111+
_id: protectString('mockPartInstanceId'),
112+
part: createMockPart(),
113+
segmentId: protectString('mockSegmentId'),
114+
rundownId: protectString('mockRundownId'),
115+
takeCount: 0,
116+
rehearsal: false,
117+
playlistActivationId: protectString('mockPlaylistActivationId'),
118+
segmentPlayoutId: protectString('mockSegmentPlayoutId'),
119+
} satisfies PlayoutPartInstanceModel['partInstance'],
120+
pieceInstances: [] satisfies PlayoutPartInstanceModel['pieceInstances'],
121+
122+
recalculateExpectedDurationWithTransition: jest.fn(),
123+
snapshotMakeCopy: jest.fn(() => Date.now() as any),
124+
snapshotRestore: jest.fn(() => {
125+
throw new Error('snapshotRestore not expected')
126+
}),
127+
},
128+
mockOptions
129+
)
130+
}
131+
132+
test('successful with empty blueprint method', async () => {
133+
const context = setupDefaultJobEnvironment()
134+
const showStyleCompound = await setupMockShowStyleCompound(context)
135+
136+
const syncIngestUpdateToPartInstanceFn = jest.fn()
137+
context.updateShowStyleBlueprint({
138+
syncIngestUpdateToPartInstance: syncIngestUpdateToPartInstanceFn,
139+
})
140+
const blueprint = await context.getShowStyleBlueprint(showStyleCompound._id)
141+
142+
const playoutModel = createMockPlayoutModel()
143+
const ingestModel = createMockIngestModelReadonly()
144+
const rundownModel = createMockPlayoutRundownModel()
145+
146+
const worker = new SyncChangesToPartInstancesWorker(
147+
context,
148+
playoutModel,
149+
ingestModel,
150+
rundownModel,
151+
showStyleCompound,
152+
blueprint
153+
)
154+
155+
const partInstance = createMockPartInstance()
156+
const part = createMockPart()
157+
158+
const instanceToSync: PartInstanceToSync = {
159+
playoutRundownModel: rundownModel,
160+
existingPartInstance: partInstance,
161+
previousPartInstance: null,
162+
playStatus: 'next',
163+
newPart: part,
164+
proposedPieceInstances: Promise.resolve([]),
165+
}
166+
167+
await worker.syncChangesToPartInstance(instanceToSync)
168+
169+
expect(partInstance.snapshotMakeCopy).toHaveBeenCalledTimes(1)
170+
expect(partInstance.snapshotRestore).toHaveBeenCalledTimes(0)
171+
expect(syncIngestUpdateToPartInstanceFn).toHaveBeenCalledTimes(1)
172+
expect(validateAdlibTestingPartInstanceProperties).toHaveBeenCalledTimes(1)
173+
})
174+
})
175+
})

0 commit comments

Comments
 (0)