|
8 | 8 | import { EmptyPieceTimelineObjectsBlob } from '@sofie-automation/corelib/dist/dataModel/Piece' |
9 | 9 | import { literal, getRandomId, getRandomString } from '@sofie-automation/corelib/dist/lib' |
10 | 10 | import { LogLevel } from '@sofie-automation/meteor-lib/dist/lib' |
11 | | -import { protectString, ProtectedString } from '@sofie-automation/corelib/dist/protectedString' |
| 11 | +import { protectString, ProtectedString, unprotectString } from '@sofie-automation/corelib/dist/protectedString' |
12 | 12 | import { getCurrentTime } from '../../lib/lib' |
13 | 13 | import { waitUntil } from '../../../__mocks__/helpers/jest' |
14 | 14 | import { setupDefaultStudioEnvironment, DefaultEnvironment } from '../../../__mocks__/helpers/database' |
@@ -45,7 +45,9 @@ import { |
45 | 45 | RundownPlaylists, |
46 | 46 | Rundowns, |
47 | 47 | Segments, |
| 48 | + Studios, |
48 | 49 | } from '../../collections' |
| 50 | +import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides' |
49 | 51 | import { SupressLogMessages } from '../../../__mocks__/suppressLogging' |
50 | 52 | import { JSONBlobStringify } from '@sofie-automation/shared-lib/dist/lib/JSONBlob' |
51 | 53 | import { PeripheralDeviceCommand } from '@sofie-automation/corelib/dist/dataModel/PeripheralDeviceCommand' |
@@ -165,6 +167,7 @@ describe('test peripheralDevice general API methods', () => { |
165 | 167 | name: 'Earth', |
166 | 168 | }) |
167 | 169 | }) |
| 170 | + |
168 | 171 | beforeEach(async () => { |
169 | 172 | QueueStudioJobSpy.mockReset() |
170 | 173 | QueueStudioJobSpy.mockClear() |
@@ -745,4 +748,50 @@ describe('test peripheralDevice general API methods', () => { |
745 | 748 | }) |
746 | 749 | }) |
747 | 750 | }) |
| 751 | + |
| 752 | + describe('auto-assign devices', () => { |
| 753 | + beforeEach(async () => { |
| 754 | + env = await setupDefaultStudioEnvironment() |
| 755 | + }) |
| 756 | + |
| 757 | + test('initialize auto-assign to single studio', async () => { |
| 758 | + if (DEBUG) setLogLevel(LogLevel.DEBUG) |
| 759 | + |
| 760 | + // Prepare a new device id, not present in the DB yet |
| 761 | + const newDeviceId = getRandomId() |
| 762 | + const token = getRandomString() |
| 763 | + const options: PeripheralDeviceInitOptions = { |
| 764 | + category: PeripheralDeviceCategory.PLAYOUT, |
| 765 | + type: PeripheralDeviceType.PLAYOUT, |
| 766 | + subType: 'test', |
| 767 | + name: 'autoAssignDevice', |
| 768 | + connectionId: 'testconn', |
| 769 | + configManifest: { |
| 770 | + deviceConfigSchema: JSONBlobStringify({}), |
| 771 | + subdeviceManifest: {}, |
| 772 | + }, |
| 773 | + documentationUrl: 'http://example.com', |
| 774 | + } |
| 775 | + |
| 776 | + // Ensure it's not present yet |
| 777 | + expect(await PeripheralDevices.findOneAsync(newDeviceId)).toBeFalsy() |
| 778 | + |
| 779 | + // Initialize the device |
| 780 | + await MeteorCall.peripheralDevice.initialize(newDeviceId, token, options) |
| 781 | + |
| 782 | + // Ensure the device exists and is assigned to the only studio in the db |
| 783 | + const initDevice = (await PeripheralDevices.findOneAsync(newDeviceId)) as PeripheralDevice |
| 784 | + expect(initDevice).toBeTruthy() |
| 785 | + expect(initDevice.studioAndConfigId).toBeTruthy() |
| 786 | + expect(initDevice.studioAndConfigId!.studioId).toBe(env.studio._id) |
| 787 | + |
| 788 | + // Ensure it is created in the "parent devices" mapping (deviceSettings) |
| 789 | + const studio = await Studios.findOneAsync(env.studio._id) |
| 790 | + const deviceSettings = applyAndValidateOverrides(studio!.peripheralDeviceSettings.deviceSettings).obj |
| 791 | + expect(deviceSettings[unprotectString(newDeviceId)]).toBeTruthy() |
| 792 | + |
| 793 | + const playoutDevices = applyAndValidateOverrides(studio!.peripheralDeviceSettings.playoutDevices).obj |
| 794 | + expect(playoutDevices[unprotectString(newDeviceId)]).toBeFalsy() |
| 795 | + }) |
| 796 | + }) |
748 | 797 | }) |
0 commit comments