import { createOptions, setupTokens, TestTokens, TestProjectId, TestMenuId } from '../test.config'; import { DevicesService } from '../api/devices.service'; import { first } from 'lodash'; import { VideoConfigService } from '../api/videoConfig.service'; import { VideoList, CreateGateway, CreateNVR, CreateCamera, NVRInfo, CameraInfo, GroupList, CreateGroup, VendorList, CategoryList, DeviceDetail, Docs } from '../model/videoConfig.model'; jest.setTimeout(10000); const factory = createOptions(); const service = new VideoConfigService(factory); beforeAll(async () => { await setupTokens(); console.log('tokens are loaded'); console.log(TestTokens); }); test('videoConfig 00 获取文档', async () => { const result: Docs = await service.loadDocs(TestProjectId); console.log('loaded videoConfig docs', result); }); test('videoConfig 20 下发配置', async () => { const gatewayList: VideoList[] = await service.loadVideoList(TestProjectId, 'gateway'); console.log(gatewayList); const gateway = first(gatewayList); const result: any = await service.sendGatewayConfig(TestProjectId, gateway.id); console.log('loaded videoConfig docs', result); }); test('videoConfig 01 视频网关列表', async () => { const result: VideoList[] = await service.loadVideoList(TestProjectId, 'gateway'); console.log('loaded videoConfig gateway', result); }); test('videoConfig 02 硬盘录像机列表', async () => { const result: VideoList[] = await service.loadVideoList(TestProjectId, 'nvr'); console.log('loaded videoConfig nvr', result); }); test('videoConfig 03 摄像机列表', async () => { const result: VideoList[] = await service.loadVideoList(TestProjectId, 'camera'); console.log('loaded videoConfig camera', result); }); test('videoConfig 04 创建网关', async () => { const result = await service.createVideoGateway(TestProjectId, { name: `网关-${Date.now()}` }); console.log('create videoConfig gateway', result); }); test('videoConfig 05 更新网关', async () => { const gatewayList: VideoList[] = await service.loadVideoList(TestProjectId, 'gateway'); const gateway = first(gatewayList); if (gateway) { gateway.name = `网关 - ${Date.now()}`; const result = await service.createVideoGateway(TestProjectId, gateway); expect(result.name).toBe(gateway.name); } }); test('videoConfig 06 创建nvr', async () => { const request = { name: `nvr-${Date.now()}`, vendor: 1, ip: '192.168.1.1', username: 'admin', passowrd: 'admin', port: '8000', rtspPort: '554', gatewayId: '175fbe7c-809c-4329-bc9f-b62675b7383b' }; const result = await service.createVideoNVR(TestProjectId, request); console.log('create videoConfig nvr', result); }); test('videoConfig 07 更新nvr', async () => { const nvrList: VideoList[] = await service.loadVideoList(TestProjectId, 'nvr'); const nvr = first(nvrList); if (nvr) { const nvrInfo: NVRInfo = await service.loadNVRDeviceInfo(TestProjectId, nvr.id); nvrInfo.name = `nvr - ${Date.now()}`; const result = await service.createVideoNVR(TestProjectId, nvrInfo); expect(result.name).toBe(nvr.name); } }); test('videoConfig 08 创建摄像机', async () => { const nvrList: VideoList[] = await service.loadVideoList(TestProjectId, 'nvr'); const nvr = first(nvrList); const groupList: GroupList[] = await service.loadGroupList(TestProjectId); const group = first(groupList); const categoryList: CategoryList[] = await service.loadCategoryList(); const category = first(categoryList); const request = { name: `nvr-${Date.now()}`, nvrId: nvr.id, groupId: group.id, vendor: 1, channel: 0, category: 1, ip: '192.168.1.1', rtspPort: '554', username: 'admin', passowrd: '123123', port: '8000' }; const result = await service.createVideoCamera(TestProjectId, request); console.log('create videoConfig camera', result); }); test('videoConfig 09 更新摄像机', async () => { const nvrList: VideoList[] = await service.loadVideoList(TestProjectId, 'nvr'); const nvr = first(nvrList); if (nvr) { const nvrInfo: NVRInfo = await service.loadNVRDeviceInfo(TestProjectId, nvr.id); nvrInfo.name = `nvr - ${Date.now()}`; const result = await service.createVideoNVR(TestProjectId, nvrInfo); expect(result.name).toBe(nvr.name); } }); test('videoConfig 10 同步筑联数据信息', async () => { const result = await service.syncVideoData(TestProjectId); console.log('同步筑联数据信息', result); }); test('videoConfig 11 删除geteway设备信息', async () => { const getewayList: VideoList[] = await service.loadVideoList(TestProjectId, 'geteway'); const geteway = first(getewayList); console.log('deleting geteway', geteway.id); await service.deleteVideoDevice(TestProjectId, geteway.id); }); test('videoConfig 12 删除nvr设备信息', async () => { const nvrList: VideoList[] = await service.loadVideoList(TestProjectId, 'nvr'); const nvr = first(nvrList); console.log('deleting nvr', nvr.id); await service.deleteVideoDevice(TestProjectId, nvr.id); // 测试设备已经删除 let nullDevice = null; try { nullDevice = await service.loadNVRDeviceInfo(TestProjectId, nvr.id); } catch (e) { } finally { expect(nullDevice).toBeNull(); } }); test('videoConfig 13 删除camera设备信息', async () => { const cameraList: VideoList[] = await service.loadVideoList(TestProjectId, 'camera'); const camera = first(cameraList); console.log('deleting nvr', camera.id); await service.deleteVideoDevice(TestProjectId, camera.id); // 测试设备已经删除 let nullDevice = null; try { nullDevice = await service.loadCameraDeviceInfo(TestProjectId, camera.id); } catch (e) { } finally { expect(nullDevice).toBeNull(); } }); test('videoConfig 14 获取群组列表', async () => { const result: GroupList[] = await service.loadGroupList(TestProjectId); console.log('loaded videoConfig camera', result); }); test('videoConfig 15 创建群组', async () => { const result = await service.createGroup(TestProjectId, { name: `群组-${Date.now()}` }); console.log('create videoConfig group', result); }); test('videoConfig 15 更新群组', async () => { const groupList: GroupList[] = await service.loadGroupList(TestProjectId); const group = first(groupList); if (group) { group.name = `群组 - ${Date.now()}`; const result = await service.createGroup(TestProjectId, group); expect(result.name).toBe(group.name); } }); test('videoConfig 16 获取vendor厂家信息列表', async () => { const result: VendorList[] = await service.loadVendorList(); console.log('获取vendor厂家信息列表', result); }); test('videoConfig 17 获取Category信息列表', async () => { const result: CategoryList[] = await service.loadCategoryList(); console.log('获取Category信息列表', result); }); test('videoConfig 18 获取设备详情信息', async () => { const cameraList: VideoList[] = await service.loadVideoList(TestProjectId, 'camera'); const camera = first(cameraList); const result: DeviceDetail = await service.loadDeviceDetail(TestProjectId, camera.id); console.log('获取设备详情信息', result); }); test('videoConfig 19 删除camera分组', async () => { const groupList: GroupList[] = await service.loadGroupList(TestProjectId); const group = first(groupList); console.log('deleting geteway', group.id); await service.deleteGroup(TestProjectId, group.id); });