Skip to content

Commit 8dcf8c7

Browse files
committed
chore: fix failing test
1 parent 826d602 commit 8dcf8c7

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

meteor/server/__tests__/cronjobs.test.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import '../../__mocks__/_extendJest'
22
import { runAllTimers, waitUntil } from '../../__mocks__/helpers/jest'
33
import { MeteorMock } from '../../__mocks__/meteor'
44
import { logger } from '../logging'
5-
import { getRandomId, getRandomString, protectString } from '../lib/tempLib'
5+
import { getRandomId, getRandomString, literal, protectString } from '../lib/tempLib'
66
import { SnapshotType } from '@sofie-automation/meteor-lib/dist/collections/Snapshots'
77
import { IBlueprintPieceType, PieceLifespan, StatusCode, TSR } from '@sofie-automation/blueprints-integration'
88
import {
@@ -64,26 +64,36 @@ import {
6464
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
6565
import { Settings } from '../Settings'
6666
import { SofieIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/SofieIngestDataCache'
67+
import { ObjectOverrideSetOp } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
6768

6869
describe('cronjobs', () => {
6970
let env: DefaultEnvironment
7071
let rundownId: RundownId
7172

72-
beforeAll(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+
beforeAll(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
@@ -591,15 +601,7 @@ describe('cronjobs', () => {
591601
})
592602
test('Does not attempt to restart CasparCG when job is disabled', async () => {
593603
await createMockPlayoutGatewayAndDevices(Date.now()) // Some time after the threshold
594-
await CoreSystem.updateAsync(
595-
{},
596-
{
597-
$set: {
598-
'cron.casparCGRestart.enabled': false,
599-
},
600-
},
601-
{ multi: true }
602-
)
604+
await setCasparCGCronEnabled(false)
603605
;(logger.info as jest.Mock).mockClear()
604606
// set time to 2020/07/{date} 04:05 Local Time, should be more than 24 hours after 2020/07/19 00:00 UTC
605607
mockCurrentTime = new Date(2020, 6, date++, 4, 5, 0).getTime()

0 commit comments

Comments
 (0)