20 lines
1.3 KiB
JavaScript
20 lines
1.3 KiB
JavaScript
import { clearCredentialMap, createBatchPayload, credentialPayload, normalizeImportRows } from '@/views/sense/provisioning/provisioningPayload'
|
|
|
|
describe('Sense provisioning payloads', () => {
|
|
test('normalizes Chinese template headers and excludes unknown columns', () => {
|
|
const rows = normalizeImportRows([{ 序号: 3, 设备名称: ' 东门摄像机 ', 安装位置: ' 东门 ', ONVIF地址: 'http://192.0.2.10/onvif', 密码: 'must-not-be-sent' }])
|
|
expect(createBatchPayload(rows, ' import-1 ')).toEqual({
|
|
idempotencyKey: 'import-1',
|
|
rows: [{ lineNumber: 3, name: '东门摄像机', location: '东门', address: 'http://192.0.2.10/onvif' }]
|
|
})
|
|
})
|
|
|
|
test('credential payload is allowlisted and can be cleared in place', () => {
|
|
const values = { item1: { onvifUsername: 'installer', onvifPassword: 'temporary-secret', rtspSameAsOnvif: true, rtspUsername: 'ignored', rtspPassword: 'ignored', unexpected: 'ignored' }}
|
|
expect(credentialPayload([{ id: 'item1' }], values)).toEqual({ credentials: [{ itemId: 'item1', onvifUsername: 'installer', onvifPassword: 'temporary-secret', rtspSameAsOnvif: true, rtspUsername: '', rtspPassword: '' }] })
|
|
clearCredentialMap(values)
|
|
expect(values.item1.onvifPassword).toBe('')
|
|
expect(values.item1.onvifUsername).toBe('')
|
|
})
|
|
})
|