Skip to content

Commit bfda2d1

Browse files
committed
wip: fix tests
1 parent 4fda19d commit bfda2d1

File tree

7 files changed

+98
-103
lines changed

7 files changed

+98
-103
lines changed

meteor/server/__tests__/cronjobs.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ describe('cronjobs', () => {
466466
expect(await Snapshots.findOneAsync(snapshot1)).toBeUndefined()
467467
})
468468
async function insertPlayoutDevice(
469-
props: Pick<PeripheralDevice, 'subType' | 'deviceName' | 'lastSeen' | 'parentDeviceId'>
469+
props: Pick<PeripheralDevice, 'subType' | 'deviceName' | 'lastSeen' | 'parentDeviceId'> &
470+
Partial<Pick<PeripheralDevice, 'token'>>
470471
): Promise<PeripheralDeviceId> {
471472
const deviceId = protectString<PeripheralDeviceId>(getRandomString())
472473
await PeripheralDevices.insertAsync({
@@ -495,37 +496,43 @@ describe('cronjobs', () => {
495496
}
496497

497498
async function createMockPlayoutGatewayAndDevices(lastSeen: number): Promise<{
499+
deviceToken: string
498500
mockPlayoutGw: PeripheralDeviceId
499501
mockCasparCg: PeripheralDeviceId
500502
mockAtem: PeripheralDeviceId
501503
}> {
504+
const deviceToken = 'token1'
502505
const mockPlayoutGw = await insertPlayoutDevice({
503506
deviceName: 'Playout Gateway',
504507
lastSeen: lastSeen,
505508
subType: PERIPHERAL_SUBTYPE_PROCESS,
509+
token: deviceToken,
506510
})
507511
const mockCasparCg = await insertPlayoutDevice({
508512
deviceName: 'CasparCG',
509513
lastSeen: lastSeen,
510514
subType: TSR.DeviceType.CASPARCG,
511515
parentDeviceId: mockPlayoutGw,
516+
token: deviceToken,
512517
})
513518
const mockAtem = await insertPlayoutDevice({
514519
deviceName: 'ATEM',
515520
lastSeen: lastSeen,
516521
subType: TSR.DeviceType.ATEM,
517522
parentDeviceId: mockPlayoutGw,
523+
token: deviceToken,
518524
})
519525

520526
return {
527+
deviceToken,
521528
mockPlayoutGw,
522529
mockCasparCg,
523530
mockAtem,
524531
}
525532
}
526533

527534
test('Attempts to restart CasparCG when job is enabled', async () => {
528-
const { mockCasparCg } = await createMockPlayoutGatewayAndDevices(Date.now()) // Some time after the threshold
535+
const { mockCasparCg, deviceToken } = await createMockPlayoutGatewayAndDevices(Date.now()) // Some time after the threshold
529536

530537
;(logger.info as jest.Mock).mockClear()
531538
// set time to 2020/07/{date} 04:05 Local Time, should be more than 24 hours after 2020/07/19 00:00 UTC
@@ -548,7 +555,7 @@ describe('cronjobs', () => {
548555
Meteor.callAsync(
549556
'peripheralDevice.functionReply',
550557
cmd.deviceId, // deviceId
551-
'', // deviceToken
558+
deviceToken, // deviceToken
552559
cmd._id, // commandId
553560
null, // err
554561
null // result

meteor/server/api/__tests__/peripheralDevice.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ describe('test peripheralDevice general API methods', () => {
618618
const deviceObj = await PeripheralDevices.findOneAsync(device?._id)
619619
expect(deviceObj).toBeDefined()
620620

621-
await MeteorCall.peripheralDevice.removePeripheralDevice(device?._id)
621+
await MeteorCall.peripheralDevice.removePeripheralDevice(device._id, device.token)
622622
}
623623

624624
{

meteor/server/api/blueprints/__tests__/http.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jest.mock('../../deviceTriggers/observer')
88
import * as api from '../api'
99
jest.mock('../api.ts')
1010

11-
const DEFAULT_CONTEXT = { userId: '' }
11+
const DEFAULT_CONTEXT = expect.objectContaining({ req: expect.any(Object), res: expect.any(Object) })
1212

1313
require('../http.ts') // include in order to create the Meteor methods needed
1414

meteor/server/api/mediaManager.ts

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,74 @@ import { MediaWorkFlows, PeripheralDevices } from '../collections'
44
import { executePeripheralDeviceFunction } from './peripheralDevice/executeFunction'
55
import { MediaWorkFlowId, OrganizationId, PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
66

7-
export namespace MediaManagerAPI {
8-
export async function restartAllWorkflows(organizationId: OrganizationId | null): Promise<void> {
9-
const devices: Array<Pick<PeripheralDevice, '_id'>> = await PeripheralDevices.findFetchAsync(
10-
organizationId ? { organizationId: organizationId } : {},
11-
{
12-
fields: {
13-
_id: 1,
14-
},
15-
}
16-
)
17-
const workflows: Array<Pick<MediaWorkFlow, 'deviceId'>> = await MediaWorkFlows.findFetchAsync(
18-
{
19-
deviceId: { $in: devices.map((d) => d._id) },
7+
export async function restartAllWorkflows(organizationId: OrganizationId | null): Promise<void> {
8+
const devices: Array<Pick<PeripheralDevice, '_id'>> = await PeripheralDevices.findFetchAsync(
9+
organizationId ? { organizationId: organizationId } : {},
10+
{
11+
fields: {
12+
_id: 1,
2013
},
21-
{
22-
fields: {
23-
deviceId: 1,
24-
},
25-
}
26-
)
14+
}
15+
)
16+
const workflows: Array<Pick<MediaWorkFlow, 'deviceId'>> = await MediaWorkFlows.findFetchAsync(
17+
{
18+
deviceId: { $in: devices.map((d) => d._id) },
19+
},
20+
{
21+
fields: {
22+
deviceId: 1,
23+
},
24+
}
25+
)
2726

28-
const deviceIds = Array.from(new Set(workflows.map((w) => w.deviceId)))
27+
const deviceIds = Array.from(new Set(workflows.map((w) => w.deviceId)))
2928

30-
await Promise.all(
31-
deviceIds.map(async (deviceId) => executePeripheralDeviceFunction(deviceId, 'restartAllWorkflows'))
32-
)
33-
}
34-
export async function abortAllWorkflows(organizationId: OrganizationId | null): Promise<void> {
35-
const devices: Array<Pick<PeripheralDevice, '_id'>> = await PeripheralDevices.findFetchAsync(
36-
organizationId ? { organizationId: organizationId } : {},
37-
{
38-
fields: {
39-
_id: 1,
40-
},
41-
}
42-
)
43-
const workflows: Array<Pick<MediaWorkFlow, 'deviceId'>> = await MediaWorkFlows.findFetchAsync(
44-
{
45-
deviceId: { $in: devices.map((d) => d._id) },
29+
await Promise.all(
30+
deviceIds.map(async (deviceId) => executePeripheralDeviceFunction(deviceId, 'restartAllWorkflows'))
31+
)
32+
}
33+
export async function abortAllWorkflows(organizationId: OrganizationId | null): Promise<void> {
34+
const devices: Array<Pick<PeripheralDevice, '_id'>> = await PeripheralDevices.findFetchAsync(
35+
organizationId ? { organizationId: organizationId } : {},
36+
{
37+
fields: {
38+
_id: 1,
39+
},
40+
}
41+
)
42+
const workflows: Array<Pick<MediaWorkFlow, 'deviceId'>> = await MediaWorkFlows.findFetchAsync(
43+
{
44+
deviceId: { $in: devices.map((d) => d._id) },
45+
},
46+
{
47+
fields: {
48+
deviceId: 1,
4649
},
47-
{
48-
fields: {
49-
deviceId: 1,
50-
},
51-
}
52-
)
50+
}
51+
)
52+
53+
const deviceIds = Array.from(new Set(workflows.map((w) => w.deviceId)))
54+
55+
await Promise.all(deviceIds.map(async (deviceId) => executePeripheralDeviceFunction(deviceId, 'abortAllWorkflows')))
56+
}
5357

54-
const deviceIds = Array.from(new Set(workflows.map((w) => w.deviceId)))
58+
export async function restartWorkflow(deviceId: PeripheralDeviceId, workflowId: MediaWorkFlowId): Promise<void> {
59+
await ensureWorkflowExists(workflowId)
5560

56-
await Promise.all(
57-
deviceIds.map(async (deviceId) => executePeripheralDeviceFunction(deviceId, 'abortAllWorkflows'))
58-
)
59-
}
61+
await executePeripheralDeviceFunction(deviceId, 'restartWorkflow', workflowId)
62+
}
63+
export async function abortWorkflow(deviceId: PeripheralDeviceId, workflowId: MediaWorkFlowId): Promise<void> {
64+
await ensureWorkflowExists(workflowId)
65+
66+
await executePeripheralDeviceFunction(deviceId, 'abortWorkflow', workflowId)
67+
}
68+
export async function prioritizeWorkflow(deviceId: PeripheralDeviceId, workflowId: MediaWorkFlowId): Promise<void> {
69+
await ensureWorkflowExists(workflowId)
70+
71+
await executePeripheralDeviceFunction(deviceId, 'prioritizeWorkflow', workflowId)
72+
}
6073

61-
export async function restartWorkflow(deviceId: PeripheralDeviceId, workflowId: MediaWorkFlowId): Promise<void> {
62-
await executePeripheralDeviceFunction(deviceId, 'restartWorkflow', workflowId)
63-
}
64-
export async function abortWorkflow(deviceId: PeripheralDeviceId, workflowId: MediaWorkFlowId): Promise<void> {
65-
await executePeripheralDeviceFunction(deviceId, 'abortWorkflow', workflowId)
66-
}
67-
export async function prioritizeWorkflow(deviceId: PeripheralDeviceId, workflowId: MediaWorkFlowId): Promise<void> {
68-
await executePeripheralDeviceFunction(deviceId, 'prioritizeWorkflow', workflowId)
69-
}
74+
async function ensureWorkflowExists(workflowId: MediaWorkFlowId): Promise<void> {
75+
const doc = await MediaWorkFlows.findOneAsync(workflowId, { projection: { _id: 1 } })
76+
if (!doc) throw new Error(`Workflow "${workflowId}" not found`)
7077
}

meteor/server/api/packageManager.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,27 @@ import { PeripheralDevices } from '../collections'
77
import { executePeripheralDeviceFunction } from './peripheralDevice/executeFunction'
88
import { PeripheralDeviceId, StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
99

10-
export namespace PackageManagerAPI {
11-
export async function restartExpectation(deviceId: PeripheralDeviceId, workId: string): Promise<void> {
12-
await executePeripheralDeviceFunction(deviceId, 'restartExpectation', workId)
13-
}
14-
export async function abortExpectation(deviceId: PeripheralDeviceId, workId: string): Promise<any> {
15-
await executePeripheralDeviceFunction(deviceId, 'abortExpectation', workId)
16-
}
10+
export async function restartExpectation(deviceId: PeripheralDeviceId, workId: string): Promise<void> {
11+
await executePeripheralDeviceFunction(deviceId, 'restartExpectation', workId)
12+
}
13+
export async function abortExpectation(deviceId: PeripheralDeviceId, workId: string): Promise<any> {
14+
await executePeripheralDeviceFunction(deviceId, 'abortExpectation', workId)
15+
}
1716

18-
export async function restartAllExpectationsInStudio(studioId: StudioId): Promise<void> {
19-
const packageManagerDevices = await PeripheralDevices.findFetchAsync({
20-
studioId: studioId,
21-
category: PeripheralDeviceCategory.PACKAGE_MANAGER,
22-
type: PeripheralDeviceType.PACKAGE_MANAGER,
23-
subType: PERIPHERAL_SUBTYPE_PROCESS,
24-
})
17+
export async function restartAllExpectationsInStudio(studioId: StudioId): Promise<void> {
18+
const packageManagerDevices = await PeripheralDevices.findFetchAsync({
19+
studioId: studioId,
20+
category: PeripheralDeviceCategory.PACKAGE_MANAGER,
21+
type: PeripheralDeviceType.PACKAGE_MANAGER,
22+
subType: PERIPHERAL_SUBTYPE_PROCESS,
23+
})
2524

26-
await Promise.all(
27-
packageManagerDevices.map(async (packageManagerDevice) => {
28-
return executePeripheralDeviceFunction(packageManagerDevice._id, 'restartAllExpectations')
29-
})
30-
)
31-
}
32-
export async function restartPackageContainer(deviceId: PeripheralDeviceId, containerId: string): Promise<void> {
33-
await executePeripheralDeviceFunction(deviceId, 'restartPackageContainer', containerId)
34-
}
25+
await Promise.all(
26+
packageManagerDevices.map(async (packageManagerDevice) => {
27+
return executePeripheralDeviceFunction(packageManagerDevice._id, 'restartAllExpectations')
28+
})
29+
)
30+
}
31+
export async function restartPackageContainer(deviceId: PeripheralDeviceId, containerId: string): Promise<void> {
32+
await executePeripheralDeviceFunction(deviceId, 'restartPackageContainer', containerId)
3533
}

meteor/server/api/rest/v0/__tests__/rest.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,6 @@ describe('REST API', () => {
2020

2121
const legacyApiRouter = createLegacyApiRouter()
2222

23-
test('registers endpoints for all UserActionAPI methods', async () => {
24-
for (const [methodName, methodValue] of Object.entries<any>(UserActionAPIMethods)) {
25-
const signature = MeteorMethodSignatures[methodValue]
26-
27-
let resource = `/action/${methodName}`
28-
for (const paramName of signature || []) {
29-
resource += `/${paramName}`
30-
}
31-
32-
const ctx = await callKoaRoute(legacyApiRouter, {
33-
method: 'POST',
34-
url: resource,
35-
})
36-
expect(ctx.response.status).not.toBe(404)
37-
}
38-
})
39-
4023
test('calls the UserActionAPI methods, when doing a POST to the endpoint', async () => {
4124
for (const [methodName, methodValue] of Object.entries<any>(UserActionAPIMethods)) {
4225
const signature = MeteorMethodSignatures[methodValue]

meteor/server/api/userActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { storeRundownPlaylistSnapshot } from './snapshot'
1010
import { registerClassToMeteorMethods, ReplaceOptionalWithNullInMethodArguments } from '../methods'
1111
import { ServerRundownAPI } from './rundown'
1212
import { saveEvaluation } from './evaluations'
13-
import { MediaManagerAPI } from './mediaManager'
13+
import * as MediaManagerAPI from './mediaManager'
1414
import { MOSDeviceActions } from './ingest/mosDevice/actions'
1515
import { MethodContextAPI } from './methodContext'
1616
import { ServerClientAPI } from './client'
@@ -21,7 +21,7 @@ import { BucketAdLib } from '@sofie-automation/corelib/dist/dataModel/BucketAdLi
2121
import { AdLibActionCommon } from '@sofie-automation/corelib/dist/dataModel/AdlibAction'
2222
import { BucketAdLibAction } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibAction'
2323
import { checkAccessToRundown } from '../security/check'
24-
import { PackageManagerAPI } from './packageManager'
24+
import * as PackageManagerAPI from './packageManager'
2525
import { ServerPeripheralDeviceAPI } from './peripheralDevice'
2626
import { StudioJobs } from '@sofie-automation/corelib/dist/worker/studio'
2727
import {

0 commit comments

Comments
 (0)