57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
import {
|
|
createDevicePayload,
|
|
credentialPayload,
|
|
disableDevicePayload,
|
|
updateDevicePayload
|
|
} from '@/views/sense/device/devicePayload'
|
|
|
|
describe('Sense device payload allowlists', () => {
|
|
const form = {
|
|
id: 'read-only-id',
|
|
name: '东门摄像机',
|
|
location: '教学楼一楼东门',
|
|
modality: 'video',
|
|
capabilities: ['video'],
|
|
version: 9,
|
|
adapterStatus: 'ready',
|
|
unexpected: 'must-not-be-sent'
|
|
}
|
|
|
|
test('create keeps Chinese fields and only writable create fields', () => {
|
|
expect(createDevicePayload(form)).toEqual({
|
|
name: '东门摄像机',
|
|
location: '教学楼一楼东门',
|
|
modality: 'video',
|
|
capabilities: ['video']
|
|
})
|
|
})
|
|
|
|
test('update excludes id, modality and server state while carrying version', () => {
|
|
expect(updateDevicePayload(form)).toEqual({
|
|
name: '东门摄像机',
|
|
location: '教学楼一楼东门',
|
|
capabilities: ['video'],
|
|
version: 9
|
|
})
|
|
})
|
|
|
|
test('credential payload does not send unused RTSP fields', () => {
|
|
expect(credentialPayload({
|
|
onvifUsername: 'synthetic-user',
|
|
onvifPassword: 'synthetic-password',
|
|
rtspSameAsOnvif: true,
|
|
rtspUsername: 'must-not-be-sent',
|
|
rtspPassword: 'must-not-be-sent',
|
|
version: 9
|
|
})).toEqual({
|
|
onvifUsername: 'synthetic-user',
|
|
onvifPassword: 'synthetic-password',
|
|
rtspSameAsOnvif: true,
|
|
rtspUsername: '',
|
|
rtspPassword: '',
|
|
version: 9
|
|
})
|
|
expect(disableDevicePayload(9)).toEqual({ version: 9 })
|
|
})
|
|
})
|