Sfoglia il codice sorgente

refactor(camera): update camera API tests to align with new endpoint structure

- Modified test cases to reflect changes in camera API endpoints, including updates to the paths for getting camera details and PTZ control actions.
- Introduced new mock functions for PTZ requests to support the updated API interactions.
- Ensured consistency in test descriptions and expectations for improved clarity.
yb 3 giorni fa
parent
commit
fd7dc2b772
1 ha cambiato i file con 17 aggiunte e 10 eliminazioni
  1. 17 10
      tests/unit/api/camera.spec.ts

+ 17 - 10
tests/unit/api/camera.spec.ts

@@ -18,7 +18,9 @@ import { mockCameras, mockChannels, wrapResponse } from '../../fixtures'
 
 vi.mock('@/utils/request', () => ({
   get: vi.fn(),
-  post: vi.fn()
+  post: vi.fn(),
+  ptzGet: vi.fn(),
+  ptzPost: vi.fn()
 }))
 
 describe('Camera API', () => {
@@ -48,14 +50,14 @@ describe('Camera API', () => {
     })
 
     describe('getCamera', () => {
-      it('should call GET /camera/control/:id', async () => {
+      it('should call GET /cameras/:id', async () => {
         const camera = mockCameras[0]
         const mockResponse = wrapResponse(camera)
         vi.mocked(request.get).mockResolvedValue(mockResponse)
 
         const result = await getCamera(camera.cameraId)
 
-        expect(request.get).toHaveBeenCalledWith(`/camera/control/${camera.cameraId}`)
+        expect(request.get).toHaveBeenCalledWith(`/cameras/${camera.cameraId}`)
         expect(result.data.cameraId).toBe(camera.cameraId)
       })
     })
@@ -90,26 +92,31 @@ describe('Camera API', () => {
     })
 
     describe('ptzStart', () => {
-      it('should call POST /camera/control/:id/ptz/start', async () => {
+      it('should call POST /ptz/control with PTZ service', async () => {
         const mockResponse = wrapResponse(null)
-        vi.mocked(request.post).mockResolvedValue(mockResponse)
+        vi.mocked(request.ptzPost).mockResolvedValue(mockResponse)
 
         await ptzStart('cam-001', 'up', 50)
 
-        expect(request.post).toHaveBeenCalledWith('/camera/control/cam-001/ptz/start', undefined, {
-          params: { action: 'up', speed: 50 }
+        expect(request.ptzPost).toHaveBeenCalledWith('/ptz/control', {
+          host: 'cam-001',
+          command: 'up',
+          speed: 50
         })
       })
     })
 
     describe('ptzStop', () => {
-      it('should call POST /camera/control/:id/ptz/stop', async () => {
+      it('should call POST /ptz/control with stop command', async () => {
         const mockResponse = wrapResponse(null)
-        vi.mocked(request.post).mockResolvedValue(mockResponse)
+        vi.mocked(request.ptzPost).mockResolvedValue(mockResponse)
 
         await ptzStop('cam-001')
 
-        expect(request.post).toHaveBeenCalledWith('/camera/control/cam-001/ptz/stop')
+        expect(request.ptzPost).toHaveBeenCalledWith('/ptz/control', {
+          host: 'cam-001',
+          command: 'stop'
+        })
       })
     })
   })