@@ -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 {
@@ -61,26 +61,36 @@ import {
6161} from '../../__mocks__/helpers/database'
6262import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
6363import { Settings } from '../Settings'
64+ import { ObjectOverrideSetOp } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
6465
6566describe ( 'cronjobs' , ( ) => {
6667 let env : DefaultEnvironment
6768 let rundownId : RundownId
6869
69- beforeAllInFiber ( async ( ) => {
70- env = await setupDefaultStudioEnvironment ( )
71-
72- const o = await setupDefaultRundownPlaylist ( env )
73- rundownId = o . rundownId
74-
70+ async function setCasparCGCronEnabled ( enabled : boolean ) {
7571 await CoreSystem . updateAsync (
7672 { } ,
7773 {
78- $set : {
79- 'cron.casparCGRestart.enabled' : true ,
74+ // This is a little bit of a hack, as it will result in duplicate ops, but it's fine for unit tests
75+ $push : {
76+ 'settingsWithOverrides.overrides' : literal < ObjectOverrideSetOp > ( {
77+ op : 'set' ,
78+ path : 'cron.casparCGRestart.enabled' ,
79+ value : enabled ,
80+ } ) ,
8081 } ,
8182 } ,
8283 { multi : true }
8384 )
85+ }
86+
87+ beforeAllInFiber ( async ( ) => {
88+ env = await setupDefaultStudioEnvironment ( )
89+
90+ const o = await setupDefaultRundownPlaylist ( env )
91+ rundownId = o . rundownId
92+
93+ await setCasparCGCronEnabled ( true )
8494
8595 jest . useFakeTimers ( )
8696 // set time to 2020/07/19 00:00 Local Time
@@ -537,15 +547,7 @@ describe('cronjobs', () => {
537547 } )
538548 testInFiber ( 'Does not attempt to restart CasparCG when job is disabled' , async ( ) => {
539549 await createMockPlayoutGatewayAndDevices ( Date . now ( ) ) // Some time after the threshold
540- await CoreSystem . updateAsync (
541- { } ,
542- {
543- $set : {
544- 'cron.casparCGRestart.enabled' : false ,
545- } ,
546- } ,
547- { multi : true }
548- )
550+ await setCasparCGCronEnabled ( false )
549551 ; ( logger . info as jest . Mock ) . mockClear ( )
550552 // set time to 2020/07/{date} 04:05 Local Time, should be more than 24 hours after 2020/07/19 00:00 UTC
551553 mockCurrentTime = new Date ( 2020 , 6 , date ++ , 4 , 5 , 0 ) . getTime ( )
0 commit comments