Skip to content

Commit

Permalink
chore: fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Nov 20, 2024
1 parent 826d602 commit 8dcf8c7
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions meteor/server/__tests__/cronjobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../../__mocks__/_extendJest'
import { runAllTimers, waitUntil } from '../../__mocks__/helpers/jest'
import { MeteorMock } from '../../__mocks__/meteor'
import { logger } from '../logging'
import { getRandomId, getRandomString, protectString } from '../lib/tempLib'
import { getRandomId, getRandomString, literal, protectString } from '../lib/tempLib'
import { SnapshotType } from '@sofie-automation/meteor-lib/dist/collections/Snapshots'
import { IBlueprintPieceType, PieceLifespan, StatusCode, TSR } from '@sofie-automation/blueprints-integration'
import {
Expand Down Expand Up @@ -64,26 +64,36 @@ import {
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
import { Settings } from '../Settings'
import { SofieIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/SofieIngestDataCache'
import { ObjectOverrideSetOp } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'

describe('cronjobs', () => {
let env: DefaultEnvironment
let rundownId: RundownId

beforeAll(async () => {
env = await setupDefaultStudioEnvironment()

const o = await setupDefaultRundownPlaylist(env)
rundownId = o.rundownId

async function setCasparCGCronEnabled(enabled: boolean) {
await CoreSystem.updateAsync(
{},
{
$set: {
'cron.casparCGRestart.enabled': true,
// This is a little bit of a hack, as it will result in duplicate ops, but it's fine for unit tests
$push: {
'settingsWithOverrides.overrides': literal<ObjectOverrideSetOp>({
op: 'set',
path: 'cron.casparCGRestart.enabled',
value: enabled,
}),
},
},
{ multi: true }
)
}

beforeAll(async () => {
env = await setupDefaultStudioEnvironment()

const o = await setupDefaultRundownPlaylist(env)
rundownId = o.rundownId

await setCasparCGCronEnabled(true)

jest.useFakeTimers()
// set time to 2020/07/19 00:00 Local Time
Expand Down Expand Up @@ -591,15 +601,7 @@ describe('cronjobs', () => {
})
test('Does not attempt to restart CasparCG when job is disabled', async () => {
await createMockPlayoutGatewayAndDevices(Date.now()) // Some time after the threshold
await CoreSystem.updateAsync(
{},
{
$set: {
'cron.casparCGRestart.enabled': false,
},
},
{ multi: true }
)
await setCasparCGCronEnabled(false)
;(logger.info as jest.Mock).mockClear()
// set time to 2020/07/{date} 04:05 Local Time, should be more than 24 hours after 2020/07/19 00:00 UTC
mockCurrentTime = new Date(2020, 6, date++, 4, 5, 0).getTime()
Expand Down

0 comments on commit 8dcf8c7

Please sign in to comment.