feat: 实现 Sense 批量开通与失败重试 (#72)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import axios from 'axios'
|
||||
import { downloadProvisioningBatch } from '@/api/sense/provisioning'
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
||||
jest.mock('axios', () => ({ get: jest.fn() }))
|
||||
jest.mock('@/utils/auth', () => ({ getToken: jest.fn() }))
|
||||
jest.mock('@/utils/request', () => jest.fn())
|
||||
|
||||
describe('Sense provisioning result export', () => {
|
||||
test('downloads the audited server export as a blob', async() => {
|
||||
const blob = new Blob(['status'], { type: 'text/csv' })
|
||||
getToken.mockReturnValue('synthetic-token')
|
||||
axios.get.mockResolvedValue({ data: blob })
|
||||
await expect(downloadProvisioningBatch('batch-1')).resolves.toBe(blob)
|
||||
expect(axios.get).toHaveBeenCalledWith(expect.stringContaining('/api/v1/provisioning/batches/batch-1/export'), {
|
||||
responseType: 'blob',
|
||||
headers: { Authorization: 'Bearer synthetic-token' }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
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('')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user