@@ -2,7 +2,7 @@ import '../../__mocks__/_extendJest'
22import { testInFiber , runAllTimers , beforeAllInFiber , waitUntil } from '../../__mocks__/helpers/jest'
33import { MeteorMock } from '../../__mocks__/meteor'
44import { logger } from '../logging'
5- import { getRandomId , getRandomString , protectString } from '../lib/tempLib'
5+ import { getRandomId , getRandomString , literal , protectString } from '../lib/tempLib'
66import { SnapshotType } from '@sofie-automation/meteor-lib/dist/collections/Snapshots'
77import { IBlueprintPieceType , PieceLifespan , StatusCode , TSR } from '@sofie-automation/blueprints-integration'
88import {
@@ -64,26 +64,36 @@ import {
6464import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
6565import { Settings } from '../Settings'
6666import { SofieIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/SofieIngestDataCache'
67+ import { ObjectOverrideSetOp } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
6768
6869describe ( 'cronjobs' , ( ) => {
6970 let env : DefaultEnvironment
7071 let rundownId : RundownId
7172
72- beforeAllInFiber ( async ( ) => {
73- env = await setupDefaultStudioEnvironment ( )
74-
75- const o = await setupDefaultRundownPlaylist ( env )
76- rundownId = o . rundownId
77-
73+ async function setCasparCGCronEnabled ( enabled : boolean ) {
7874 await CoreSystem . updateAsync (
7975 { } ,
8076 {
81- $set : {
82- 'cron.casparCGRestart.enabled' : true ,
77+ // This is a little bit of a hack, as it will result in duplicate ops, but it's fine for unit tests
78+ $push : {
79+ 'settingsWithOverrides.overrides' : literal < ObjectOverrideSetOp > ( {
80+ op : 'set' ,
81+ path : 'cron.casparCGRestart.enabled' ,
82+ value : enabled ,
83+ } ) ,
8384 } ,
8485 } ,
8586 { multi : true }
8687 )
88+ }
89+
90+ beforeAllInFiber ( async ( ) => {
91+ env = await setupDefaultStudioEnvironment ( )
92+
93+ const o = await setupDefaultRundownPlaylist ( env )
94+ rundownId = o . rundownId
95+
96+ await setCasparCGCronEnabled ( true )
8797
8898 jest . useFakeTimers ( )
8999 // set time to 2020/07/19 00:00 Local Time
@@ -589,15 +599,7 @@ describe('cronjobs', () => {
589599 } )
590600 testInFiber ( 'Does not attempt to restart CasparCG when job is disabled' , async ( ) => {
591601 await createMockPlayoutGatewayAndDevices ( Date . now ( ) ) // Some time after the threshold
592- await CoreSystem . updateAsync (
593- { } ,
594- {
595- $set : {
596- 'cron.casparCGRestart.enabled' : false ,
597- } ,
598- } ,
599- { multi : true }
600- )
602+ await setCasparCGCronEnabled ( false )
601603 ; ( logger . info as jest . Mock ) . mockClear ( )
602604 // set time to 2020/07/{date} 04:05 Local Time, should be more than 24 hours after 2020/07/19 00:00 UTC
603605 mockCurrentTime = new Date ( 2020 , 6 , date ++ , 4 , 5 , 0 ) . getTime ( )
0 commit comments