Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions meteor/__mocks__/helpers/methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MethodRegistry } from '../../server/methodRegistry'
import { registerAllApiMethods } from '../../server/methodRegistrations'

/**
* Test helper: register all API methods on a fresh MethodRegistry and apply them to the (mock)
* Meteor server, mirroring what `main.ts` does at startup.
*
* Call this in suites that exercise Meteor methods (via `MeteorCall`, `Meteor.callAsync`, or by
* spying on `MeteorMock.mockMethods`). It is needed because the production registration now only
* runs explicitly from `main.ts`, rather than as an import-time side effect of each API file.
*/
export function registerAllMethodsForTest(): MethodRegistry {
const registry = new MethodRegistry()
registerAllApiMethods(registry)
registry.applyToMeteor()
return registry
}
17 changes: 17 additions & 0 deletions meteor/__mocks__/helpers/publications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PublicationRegistry } from '../../server/publicationRegistry'
import { registerAllPublications } from '../../server/publicationRegistrations'

/**
* Test helper: register all DDP publications on a fresh PublicationRegistry and apply them to the
* (mock) Meteor server, mirroring what `main.ts` does at startup.
*
* Call this in suites that exercise Meteor subscriptions. It is needed because the production
* registration now only runs explicitly from `main.ts`, rather than as an import-time side effect of
* each publication file.
*/
export function registerAllPublicationsForTest(): PublicationRegistry {
const registry = new PublicationRegistry()
registerAllPublications(registry)
registry.applyToMeteor()
return registry
}
199 changes: 199 additions & 0 deletions meteor/server/__tests__/__snapshots__/methodRegistry.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`MethodRegistry the full set of registered method names is stable (drift guard) 1`] = `
[
"blueprint.assignSystem",
"client.callBackgroundPeripheralDeviceFunction",
"client.callPeripheralDeviceAction",
"client.callPeripheralDeviceFunction",
"client.clientErrorReport",
"client.clientLogNotification",
"client.clientLogger",
"debug_clearAllResetInstances",
"debug_forceClearAllCaches",
"debug_playlistRunBlueprints",
"debug_previewTrigger",
"debug_regenerateNextPartInstance",
"debug_removeAllPlaylists",
"debug_removePlaylist",
"debug_segmentRunBlueprints",
"debug_syncPlayheadInfinitesForNextPartInstance",
"debug_updateTimeline",
"externalMessages.remove",
"externalMessages.retry",
"externalMessages.toggleHold",
"migration.fixupConfigForShowStyleBase",
"migration.fixupConfigForStudio",
"migration.forceMigration",
"migration.getMigrationStatus",
"migration.ignoreFixupConfigForShowStyleBase",
"migration.ignoreFixupConfigForStudio",
"migration.resetDatabaseVersions",
"migration.runMigration",
"migration.runUpgradeForCoreSystem",
"migration.runUpgradeForShowStyleBase",
"migration.runUpgradeForStudio",
"migration.validateConfigForShowStyleBase",
"migration.validateConfigForStudio",
"mongo.insert",
"mongo.remove",
"mongo.update",
"peripheralDevice.functionReply",
"peripheralDevice.getPeripheralDevice",
"peripheralDevice.initialize",
"peripheralDevice.input.inputDeviceTrigger",
"peripheralDevice.killProcess",
"peripheralDevice.mediaScanner.clearMediaObjectCollection",
"peripheralDevice.mediaScanner.getMediaObjectRevisions",
"peripheralDevice.mediaScanner.updateMediaObject",
"peripheralDevice.mos.roCreate",
"peripheralDevice.mos.roDelete",
"peripheralDevice.mos.roFullStory",
"peripheralDevice.mos.roItemDelete",
"peripheralDevice.mos.roItemInsert",
"peripheralDevice.mos.roItemMove",
"peripheralDevice.mos.roItemReplace",
"peripheralDevice.mos.roItemStatus",
"peripheralDevice.mos.roItemSwap",
"peripheralDevice.mos.roMetadata",
"peripheralDevice.mos.roReadyToAir",
"peripheralDevice.mos.roReplace",
"peripheralDevice.mos.roStatus",
"peripheralDevice.mos.roStoryDelete",
"peripheralDevice.mos.roStoryInsert",
"peripheralDevice.mos.roStoryMove",
"peripheralDevice.mos.roStoryReplace",
"peripheralDevice.mos.roStoryStatus",
"peripheralDevice.mos.roStorySwap",
"peripheralDevice.packageManager.fetchPackageInfoMetadata",
"peripheralDevice.packageManager.removeAllExpectedPackageWorkStatusOfDevice",
"peripheralDevice.packageManager.removeAllPackageContainerPackageStatusesOfDevice",
"peripheralDevice.packageManager.removeAllPackageContainerStatusesOfDevice",
"peripheralDevice.packageManager.removePackageInfo",
"peripheralDevice.packageManager.updateExpectedPackageWorkStatuses",
"peripheralDevice.packageManager.updatePackageContainerPackageStatuses",
"peripheralDevice.packageManager.updatePackageContainerStatuses",
"peripheralDevice.packageManager.updatePackageInfo",
"peripheralDevice.ping",
"peripheralDevice.pingWithCommand",
"peripheralDevice.playlist.playlistGet",
"peripheralDevice.playout.playbackChanged",
"peripheralDevice.playout.reportExternalEvents",
"peripheralDevice.removePeripheralDevice",
"peripheralDevice.reportResolveDone",
"peripheralDevice.rundown.partCreate",
"peripheralDevice.rundown.partDelete",
"peripheralDevice.rundown.partUpdate",
"peripheralDevice.rundown.rundownCreate",
"peripheralDevice.rundown.rundownDelete",
"peripheralDevice.rundown.rundownGet",
"peripheralDevice.rundown.rundownList",
"peripheralDevice.rundown.rundownMetaDataUpdate",
"peripheralDevice.rundown.rundownUpdate",
"peripheralDevice.rundown.segmentCreate",
"peripheralDevice.rundown.segmentDelete",
"peripheralDevice.rundown.segmentGet",
"peripheralDevice.rundown.segmentRanksUpdate",
"peripheralDevice.rundown.segmentUpdate",
"peripheralDevice.spreadsheet.requestUserAuthToken",
"peripheralDevice.spreadsheet.storeAccessToken",
"peripheralDevice.status",
"peripheralDevice.testMethod",
"peripheralDevice.timeline.setTimelineTriggerTime",
"peripheralDevice.unInitialize",
"playout.shouldUpdateStudioBaseline",
"playout.updateStudioBaseline",
"rundown.rundownPlaylistNeedsResync",
"rundownLayout.createRundownLayout",
"rundownLayout.removeRundownLayout",
"showstyles.getCreateAdlibTestingRundownOptions",
"showstyles.importShowStyleVariant",
"showstyles.importShowStyleVariantAsNew",
"showstyles.insertBlueprint",
"showstyles.insertShowStyleBase",
"showstyles.insertShowStyleVariant",
"showstyles.removeBlueprint",
"showstyles.removeShowStyleBase",
"showstyles.removeShowStyleVariant",
"showstyles.reorderShowStyleVariant",
"snapshot.debugSnaphot",
"snapshot.removeSnaphot",
"snapshot.restoreSnaphot",
"snapshot.rundownPlaylistSnapshot",
"snapshot.systemSnapshot",
"studio.assignConfigToPeripheralDevice",
"studio.insertStudio",
"studio.removeStudio",
"system.cleanupIndexes",
"system.cleanupOldData",
"system.doSystemBenchmark",
"system.generateSingleUseToken",
"system.getTranslationBundle",
"system.runCronjob",
"systemStatus.getDebugStates",
"systemStatus.getSystemStatus",
"systemTime.determineDiffTime",
"systemTime.getTime",
"systemTime.getTimeDiff",
"triggeredActions.createTriggeredActions",
"triggeredActions.removeTriggeredActions",
"user.getUserPermissions",
"userAction.DEBUG_crashStudioWorker",
"userAction.activate",
"userAction.activateAdlibTestingMode",
"userAction.activateHold",
"userAction.baselineAdLibPieceStart",
"userAction.blurred",
"userAction.bucketAdlibImport",
"userAction.bucketAdlibStart",
"userAction.bucketsModifyBucketAdLib",
"userAction.bucketsModifyBucketAdLibAction",
"userAction.bucketsSaveActionIntoBucket",
"userAction.clearQuickLoop",
"userAction.createAdlibTestingRundownForShowStyleVariant",
"userAction.createBucket",
"userAction.deactivate",
"userAction.disableNextPiece",
"userAction.emptyBucket",
"userAction.executeAction",
"userAction.executeUserChangeOperation",
"userAction.focused",
"userAction.forceResetAndActivate",
"userAction.ingest.regenerateRundownPlaylist",
"userAction.modifyBucket",
"userAction.moveNext",
"userAction.moveRundown",
"userAction.packagemanager.abortExpectation",
"userAction.packagemanager.restartAllExpectations",
"userAction.packagemanager.restartExpectation",
"userAction.packagemanager.restartPackageContainer",
"userAction.pieceSetInOutPoints",
"userAction.pieceTakeNow",
"userAction.prepareForBroadcast",
"userAction.queueNextSegment",
"userAction.removeBucket",
"userAction.removeBucketAdLib",
"userAction.removeBucketAdLibAction",
"userAction.removeRundown",
"userAction.removeRundownPlaylist",
"userAction.resetAndActivate",
"userAction.resetRundownPlaylist",
"userAction.restoreRundownOrder",
"userAction.resyncRundown",
"userAction.resyncRundownPlaylist",
"userAction.saveEvaluation",
"userAction.segmentAdLibPieceStart",
"userAction.setNext",
"userAction.setNextSegment",
"userAction.setQuickLoopEnd",
"userAction.setQuickLoopStart",
"userAction.sourceLayerOnPartStop",
"userAction.sourceLayerStickyPieceStart",
"userAction.storeRundownSnapshot",
"userAction.switchRouteSet",
"userAction.system.disablePeripheralSubDevice",
"userAction.system.restartCore",
"userAction.take",
"userAction.unsyncRundown",
]
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`PublicationRegistry the full set of registered publication names is stable (drift guard) 1`] = `
[
"adLibActions",
"adLibActionsForPart",
"adLibPieces",
"adLibPiecesForPart",
"blueprints",
"bucketAdLibActions",
"bucketAdLibPieces",
"buckets",
"coreSystem",
"deviceTriggersPreview",
"evaluations",
"expectedPackageWorkStatuses",
"expectedPackages",
"expectedPlayoutItemsForDevice",
"externalEventSubscriptionsForDevice",
"externalMessageQueue",
"ingestDataCache",
"ingestDeviceRundownStatus",
"ingestDeviceRundownStatusTestTool",
"mappingsForDevice",
"mappingsForStudio",
"mountedTriggersForDevice",
"mountedTriggersForDevicePreview",
"notificationsForRundown",
"notificationsForRundownPlaylist",
"packageContainerStatuses",
"packageInfos",
"packageManagerExpectedPackages",
"packageManagerPackageContainers",
"packageManagerPlayoutContext",
"partInstances",
"partInstancesSimple",
"parts",
"peripheralDeviceCommands",
"peripheralDeviceForDevice",
"peripheralDevices",
"peripheralDevicesAndSubDevices",
"pieceInstances",
"pieceInstancesSimple",
"pieces",
"piecesInfiniteStartingBefore",
"rundownBaselineAdLibActions",
"rundownBaselineAdLibPieces",
"rundownLayouts",
"rundownPlaylistForStudio",
"rundownPlaylists",
"rundownsForDevice",
"rundownsInPlaylists",
"rundownsWithShowStyleBases",
"segments",
"showStyleBases",
"showStyleVariants",
"snapshots",
"studios",
"timelineDatastore",
"timelineDatastoreForDevice",
"timelineForDevice",
"timelineForStudio",
"translationsBundles",
"triggeredActions",
"uiBlueprintUpgradeStatuses",
"uiBucketContentStatuses",
"uiPartInstances",
"uiParts",
"uiPieceContentStatuses",
"uiSegmentPartNotes",
"uiShowStyleBase",
"uiStudio",
"uiTriggeredActions",
"userActionsLog",
]
`;
3 changes: 2 additions & 1 deletion meteor/server/__tests__/cronjobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ jest.mock('../api/deviceTriggers/observer')
const MAX_WAIT_TIME = 4 * 1000

import '../cronjobs'
import { registerAllMethodsForTest } from '../../__mocks__/helpers/methods'

import '../api/peripheralDevice'
registerAllMethodsForTest()
import {
CoreSystem,
NrcsIngestDataCache,
Expand Down
50 changes: 50 additions & 0 deletions meteor/server/__tests__/methodRegistry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { MethodApiRegistration, MethodRegistry } from '../methodRegistry'
import { METHOD_REGISTRATIONS, registerAllApiMethods } from '../methodRegistrations'

describe('MethodRegistry', () => {
test('registers all API methods without error', () => {
const registry = new MethodRegistry()
// registerApi throws if a class method has no matching wire name, so this is itself an assertion
// that every implemented method maps to an enum entry (the historical behaviour).
expect(() => registerAllApiMethods(registry)).not.toThrow()
})

test('registered names are unique and only use known wire names', () => {
const registry = new MethodRegistry()
registerAllApiMethods(registry)
const names = registry.getAllMethodNames()

// No duplicate registrations across all APIs
expect(new Set(names).size).toBe(names.length)

// Every non-debug registered name must be a value from one of the method-name enums.
// (Debug methods are not enum-backed and are checked separately.)
const enumWireNames = new Set<string>()
for (const reg of Object.values<MethodApiRegistration<any>>(METHOD_REGISTRATIONS)) {
for (const wireName of Object.values<string>(reg.methods)) enumWireNames.add(wireName)
}
for (const name of names) {
if (registry.isDebugMethod(name)) continue
expect(enumWireNames.has(name)).toBe(true)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

// A handful of representative names must be present, guarding against an API silently
// dropping out of the registry.
expect(names).toEqual(
expect.arrayContaining([
'userAction.take',
'playout.updateStudioBaseline',
'peripheralDevice.initialize',
'system.cleanupIndexes',
])
)
})

test('the full set of registered method names is stable (drift guard)', () => {
const registry = new MethodRegistry()
registerAllApiMethods(registry)
// If this snapshot changes, a method's wire name was added, removed or renamed. That must be a
// deliberate change reviewed against the clients that depend on these exact names.
expect([...registry.getAllMethodNames()].sort()).toMatchSnapshot()
})
})
Loading