|
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,48 @@ describe('test peripheralDevice general API methods', () => { |
165 | 167 | name: 'Earth', |
166 | 168 | }) |
167 | 169 | }) |
| 170 | + |
| 171 | + test('initialize auto-assign to single studio', async () => { |
| 172 | + if (DEBUG) setLogLevel(LogLevel.DEBUG) |
| 173 | + |
| 174 | + const localEnv = await setupDefaultStudioEnvironment() |
| 175 | + // Prepare a new device id, not present in the DB yet |
| 176 | + const newDeviceId = getRandomId() |
| 177 | + const token = getRandomString() |
| 178 | + const options: PeripheralDeviceInitOptions = { |
| 179 | + category: PeripheralDeviceCategory.PLAYOUT, |
| 180 | + type: PeripheralDeviceType.PLAYOUT, |
| 181 | + subType: 'test', |
| 182 | + name: 'autoAssignDevice', |
| 183 | + connectionId: 'testconn', |
| 184 | + configManifest: { |
| 185 | + deviceConfigSchema: JSONBlobStringify({}), |
| 186 | + subdeviceManifest: {}, |
| 187 | + }, |
| 188 | + documentationUrl: 'http://example.com', |
| 189 | + } |
| 190 | + |
| 191 | + // Ensure it's not present yet |
| 192 | + expect(await PeripheralDevices.findOneAsync(newDeviceId)).toBeFalsy() |
| 193 | + |
| 194 | + // Initialize the device |
| 195 | + await MeteorCall.peripheralDevice.initialize(newDeviceId, token, options) |
| 196 | + |
| 197 | + // Ensure the device exists and is assigned to the only studio in the db |
| 198 | + const initDevice = (await PeripheralDevices.findOneAsync(newDeviceId)) as PeripheralDevice |
| 199 | + expect(initDevice).toBeTruthy() |
| 200 | + expect(initDevice.studioAndConfigId).toBeTruthy() |
| 201 | + expect(initDevice.studioAndConfigId!.studioId).toBe(localEnv.studio._id) |
| 202 | + |
| 203 | + // Ensure it is created in the "parent devices" mapping (deviceSettings) |
| 204 | + const studio = await Studios.findOneAsync(localEnv.studio._id) |
| 205 | + const deviceSettings = applyAndValidateOverrides(studio!.peripheralDeviceSettings.deviceSettings).obj |
| 206 | + expect(deviceSettings[unprotectString(newDeviceId)]).toBeTruthy() |
| 207 | + |
| 208 | + const playoutDevices = applyAndValidateOverrides(studio!.peripheralDeviceSettings.playoutDevices).obj |
| 209 | + expect(playoutDevices[unprotectString(newDeviceId)]).toBeFalsy() |
| 210 | + }) |
| 211 | + |
168 | 212 | beforeEach(async () => { |
169 | 213 | QueueStudioJobSpy.mockReset() |
170 | 214 | QueueStudioJobSpy.mockClear() |
@@ -746,3 +790,40 @@ describe('test peripheralDevice general API methods', () => { |
746 | 790 | }) |
747 | 791 | }) |
748 | 792 | }) |
| 793 | + |
| 794 | +test('initialize auto-assign to single studio', async () => { |
| 795 | + if (DEBUG) setLogLevel(LogLevel.DEBUG) |
| 796 | + |
| 797 | + const localEnv = await setupDefaultStudioEnvironment() |
| 798 | + |
| 799 | + const newDeviceId = getRandomId() |
| 800 | + const token = getRandomString() |
| 801 | + const options: PeripheralDeviceInitOptions = { |
| 802 | + category: PeripheralDeviceCategory.PLAYOUT, |
| 803 | + type: PeripheralDeviceType.PLAYOUT, |
| 804 | + subType: 'test', |
| 805 | + name: 'autoAssignDevice', |
| 806 | + connectionId: 'testconn', |
| 807 | + configManifest: { |
| 808 | + deviceConfigSchema: JSONBlobStringify({}), |
| 809 | + subdeviceManifest: {}, |
| 810 | + }, |
| 811 | + documentationUrl: 'http://example.com', |
| 812 | + } |
| 813 | + |
| 814 | + expect(await PeripheralDevices.findOneAsync(newDeviceId)).toBeFalsy() |
| 815 | + |
| 816 | + await MeteorCall.peripheralDevice.initialize(newDeviceId, token, options) |
| 817 | + |
| 818 | + const initDevice = (await PeripheralDevices.findOneAsync(newDeviceId)) as PeripheralDevice |
| 819 | + expect(initDevice).toBeTruthy() |
| 820 | + expect(initDevice.studioAndConfigId).toBeTruthy() |
| 821 | + expect(initDevice.studioAndConfigId!.studioId).toBe(localEnv.studio._id) |
| 822 | + |
| 823 | + const studio = await Studios.findOneAsync(localEnv.studio._id) |
| 824 | + const deviceSettings = applyAndValidateOverrides(studio!.peripheralDeviceSettings.deviceSettings).obj |
| 825 | + expect(deviceSettings[unprotectString(newDeviceId)]).toBeTruthy() |
| 826 | + |
| 827 | + const playoutDevices = applyAndValidateOverrides(studio!.peripheralDeviceSettings.playoutDevices).obj |
| 828 | + expect(playoutDevices[unprotectString(newDeviceId)]).toBeFalsy() |
| 829 | +}) |
0 commit comments