Skip to content

Commit

Permalink
wip: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Nov 13, 2024
1 parent 5caa566 commit 731a092
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 56 deletions.
12 changes: 10 additions & 2 deletions packages/job-worker/src/__mocks__/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { IDirectCollections } from '../db'
import {
ApmSpan,
JobContext,
JobStudio,
ProcessedShowStyleBase,
ProcessedShowStyleCompound,
ProcessedShowStyleVariant,
Expand All @@ -56,6 +57,7 @@ import { JSONBlobStringify } from '@sofie-automation/shared-lib/dist/lib/JSONBlo
import { removeRundownPlaylistFromDb } from '../ingest/__tests__/lib'
import { processShowStyleBase, processShowStyleVariant } from '../jobs/showStyle'
import { defaultStudio } from './defaultCollectionObjects'
import { convertStudioToJobStudio } from '../jobs/studio'

export function setupDefaultJobEnvironment(studioId?: StudioId): MockJobContext {
const { mockCollections, jobCollections } = getMockCollections()
Expand All @@ -75,6 +77,7 @@ export class MockJobContext implements JobContext {
#jobCollections: Readonly<IDirectCollections>
#mockCollections: Readonly<IMockCollections>
#studio: ReadonlyDeep<DBStudio>
#jobStudio: ReadonlyDeep<JobStudio>

#studioBlueprint: ReadonlyDeep<StudioBlueprintManifest>
#showStyleBlueprint: ReadonlyDeep<ShowStyleBlueprintManifest>
Expand All @@ -87,6 +90,7 @@ export class MockJobContext implements JobContext {
this.#jobCollections = jobCollections
this.#mockCollections = mockCollections
this.#studio = studio
this.#jobStudio = convertStudioToJobStudio(clone<DBStudio>(studio))

this.#studioBlueprint = MockStudioBlueprint()
this.#showStyleBlueprint = MockShowStyleBlueprint()
Expand All @@ -103,7 +107,10 @@ export class MockJobContext implements JobContext {
get studioId(): StudioId {
return this.#studio._id
}
get studio(): ReadonlyDeep<DBStudio> {
get studio(): ReadonlyDeep<JobStudio> {
return this.#jobStudio
}
get rawStudio(): ReadonlyDeep<DBStudio> {
return this.#studio
}

Expand Down Expand Up @@ -219,7 +226,7 @@ export class MockJobContext implements JobContext {
}
}
getShowStyleBlueprintConfig(showStyle: ReadonlyDeep<ProcessedShowStyleCompound>): ProcessedShowStyleConfig {
return preprocessShowStyleConfig(showStyle, this.#showStyleBlueprint, this.#studio.settings)
return preprocessShowStyleConfig(showStyle, this.#showStyleBlueprint, this.studio.settings)
}

hackPublishTimelineToFastTrack(_newTimeline: TimelineComplete): void {
Expand All @@ -244,6 +251,7 @@ export class MockJobContext implements JobContext {

setStudio(studio: ReadonlyDeep<DBStudio>): void {
this.#studio = clone(studio)
this.#jobStudio = convertStudioToJobStudio(clone<DBStudio>(studio))
}
setShowStyleBlueprint(blueprint: ReadonlyDeep<ShowStyleBlueprintManifest>): void {
this.#showStyleBlueprint = blueprint
Expand Down
4 changes: 2 additions & 2 deletions packages/job-worker/src/__mocks__/defaultCollectionObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ export function defaultStudio(_id: StudioId): DBStudio {
mappingsWithOverrides: wrapDefaultObject({}),
supportedShowStyleBase: [],
blueprintConfigWithOverrides: wrapDefaultObject({}),
settings: {
settingsWithOverrides: wrapDefaultObject({
frameRate: 25,
mediaPreviewsUrl: '',
minimumTakeSpan: DEFAULT_MINIMUM_TAKE_SPAN,
allowAdlibTestingSegment: true,
},
}),
routeSetsWithOverrides: wrapDefaultObject({}),
routeSetExclusivityGroupsWithOverrides: wrapDefaultObject({}),
packageContainersWithOverrides: wrapDefaultObject({}),
Expand Down
16 changes: 8 additions & 8 deletions packages/job-worker/src/blueprints/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe('Test blueprint config', () => {
test('compileStudioConfig', () => {
const jobContext = setupDefaultJobEnvironment()
jobContext.setStudio({
...jobContext.studio,
settings: {
...jobContext.rawStudio,
settingsWithOverrides: wrapDefaultObject({
mediaPreviewsUrl: '',
frameRate: 25,
minimumTakeSpan: DEFAULT_MINIMUM_TAKE_SPAN,
},
}),
blueprintConfigWithOverrides: wrapDefaultObject({ sdfsdf: 'one', another: 5 }),
})
jobContext.updateStudioBlueprint({
Expand All @@ -33,12 +33,12 @@ describe('Test blueprint config', () => {
test('compileStudioConfig with function', () => {
const jobContext = setupDefaultJobEnvironment()
jobContext.setStudio({
...jobContext.studio,
settings: {
...jobContext.rawStudio,
settingsWithOverrides: wrapDefaultObject({
mediaPreviewsUrl: '',
frameRate: 25,
minimumTakeSpan: DEFAULT_MINIMUM_TAKE_SPAN,
},
}),
blueprintConfigWithOverrides: wrapDefaultObject({ sdfsdf: 'one', another: 5 }),
})
jobContext.updateStudioBlueprint({
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Test blueprint config', () => {

const studioId = jobContext.studioId
jobContext.setStudio({
...jobContext.studio,
...jobContext.rawStudio,
blueprintConfigWithOverrides: wrapDefaultObject({
two: 'abc',
number: 99,
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('Test blueprint config', () => {
},
})
jobContext.setStudio({
...jobContext.studio,
...jobContext.rawStudio,
supportedShowStyleBase: [showStyle._id],
})
jobContext.updateShowStyleBlueprint({
Expand Down
3 changes: 1 addition & 2 deletions packages/job-worker/src/blueprints/__tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getHash } from '@sofie-automation/corelib/dist/lib'
import { unprotectString } from '@sofie-automation/corelib/dist/protectedString'
import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
import { MockJobContext, setupDefaultJobEnvironment } from '../../__mocks__/context'
import { getShowStyleConfigRef, getStudioConfigRef } from '../configRefs'
import { CommonContext } from '../context/CommonContext'
Expand Down Expand Up @@ -81,7 +80,7 @@ describe('Test blueprint api context', () => {

expect(context.studio).toBe(studio)
expect(context.getStudioConfig()).toBe(studioConfig)
expect(context.getStudioMappings()).toEqual(applyAndValidateOverrides(studio.mappingsWithOverrides).obj)
expect(context.getStudioMappings()).toEqual(studio.mappings)
})
test('getStudioConfigRef', () => {
const context = new StudioContext(
Expand Down
7 changes: 4 additions & 3 deletions packages/job-worker/src/ingest/__tests__/ingest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { UserErrorMessage } from '@sofie-automation/corelib/dist/error'
import { PlayoutPartInstanceModel } from '../../playout/model/PlayoutPartInstanceModel'
import { NrcsIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/NrcsIngestDataCache'
import { wrapGenericIngestJob, wrapGenericIngestJobWithPrecheck } from '../jobWrappers'
import { wrapDefaultObject } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'

const handleRemovedRundownWrapped = wrapGenericIngestJob(handleRemovedRundown)
const handleUpdatedRundownWrapped = wrapGenericIngestJob(handleUpdatedRundown)
Expand Down Expand Up @@ -121,11 +122,11 @@ describe('Test ingest actions for rundowns and segments', () => {
const showStyleCompound = await setupMockShowStyleCompound(context)

context.setStudio({
...context.studio,
settings: {
...context.rawStudio,
settingsWithOverrides: wrapDefaultObject({
...context.studio.settings,
minimumTakeSpan: 0,
},
}),
supportedShowStyleBase: [showStyleCompound._id],
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('selectShowStyleVariant', () => {
const context = setupDefaultJobEnvironment()
const showStyleCompound = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id],
})

Expand All @@ -57,7 +57,7 @@ describe('selectShowStyleVariant', () => {
const context = setupDefaultJobEnvironment()
const showStyleCompound = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [],
})

Expand All @@ -76,7 +76,7 @@ describe('selectShowStyleVariant', () => {
const context = setupDefaultJobEnvironment()
const showStyleCompound = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id],
})

Expand Down Expand Up @@ -118,7 +118,7 @@ describe('selectShowStyleVariant', () => {
const showStyleCompoundVariant2 = await setupMockShowStyleVariant(context, showStyleCompound._id)
const showStyleCompound2 = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id, showStyleCompound2._id],
})

Expand Down Expand Up @@ -153,7 +153,7 @@ describe('selectShowStyleVariant', () => {
test('no show style bases', async () => {
const context = setupDefaultJobEnvironment()
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [protectString('fakeId')],
})

Expand All @@ -176,7 +176,7 @@ describe('selectShowStyleVariant', () => {
const context = setupDefaultJobEnvironment()
const showStyleCompound = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id],
})

Expand All @@ -201,7 +201,7 @@ describe('selectShowStyleVariant', () => {
const context = setupDefaultJobEnvironment()
const showStyleCompound = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id],
})

Expand All @@ -226,7 +226,7 @@ describe('selectShowStyleVariant', () => {
const context = setupDefaultJobEnvironment()
const showStyleCompound = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id],
})

Expand All @@ -251,7 +251,7 @@ describe('selectShowStyleVariant', () => {
const context = setupDefaultJobEnvironment()
const showStyleCompound = await setupMockShowStyleCompound(context)
context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id],
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Test recieved mos ingest payloads', () => {
const showStyleCompound = await setupMockShowStyleCompound(context)

context.setStudio({
...context.studio,
...context.rawStudio,
supportedShowStyleBase: [showStyleCompound._id],
})

Expand Down
7 changes: 4 additions & 3 deletions packages/job-worker/src/playout/__tests__/playout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { PlayoutChangedType } from '@sofie-automation/shared-lib/dist/peripheral
import { ProcessedShowStyleCompound } from '../../jobs'
import { handleOnPlayoutPlaybackChanged } from '../timings'
import { sleep } from '@sofie-automation/shared-lib/dist/lib/lib'
import { wrapDefaultObject } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'

// const mockGetCurrentTime = jest.spyOn(lib, 'getCurrentTime')
const mockExecutePeripheralDeviceFunction = jest
Expand Down Expand Up @@ -98,11 +99,11 @@ describe('Playout API', () => {
context = setupDefaultJobEnvironment()

context.setStudio({
...context.studio,
settings: {
...context.rawStudio,
settingsWithOverrides: wrapDefaultObject({
...context.studio.settings,
minimumTakeSpan: 0,
},
}),
})

// Ignore event jobs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Lookahead', () => {
}
}
context.setStudio({
...context.studio,
...context.rawStudio,
mappingsWithOverrides: wrapDefaultObject(mappings),
})

Expand Down Expand Up @@ -222,7 +222,7 @@ describe('Lookahead', () => {

// Set really low
{
const studio = clone<DBStudio>(context.studio)
const studio = clone<DBStudio>(context.rawStudio)
studio.mappingsWithOverrides.defaults['WHEN_CLEAR'].lookaheadMaxSearchDistance = 0
studio.mappingsWithOverrides.defaults['PRELOAD'].lookaheadMaxSearchDistance = 0
context.setStudio(studio)
Expand All @@ -236,7 +236,7 @@ describe('Lookahead', () => {
// really high
getOrderedPartsAfterPlayheadMock.mockClear()
{
const studio = clone<DBStudio>(context.studio)
const studio = clone<DBStudio>(context.rawStudio)
studio.mappingsWithOverrides.defaults['WHEN_CLEAR'].lookaheadMaxSearchDistance = -1
studio.mappingsWithOverrides.defaults['PRELOAD'].lookaheadMaxSearchDistance = 2000
context.setStudio(studio)
Expand All @@ -250,7 +250,7 @@ describe('Lookahead', () => {
// unset
getOrderedPartsAfterPlayheadMock.mockClear()
{
const studio = clone<DBStudio>(context.studio)
const studio = clone<DBStudio>(context.rawStudio)
studio.mappingsWithOverrides.defaults['WHEN_CLEAR'].lookaheadMaxSearchDistance = undefined
studio.mappingsWithOverrides.defaults['PRELOAD'].lookaheadMaxSearchDistance = -1
context.setStudio(studio)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('getOrderedPartsAfterPlayhead', () => {
}
}
context.setStudio({
...context.studio,
...context.rawStudio,
mappingsWithOverrides: wrapDefaultObject(mappings),
})

Expand Down
Loading

0 comments on commit 731a092

Please sign in to comment.