Просмотр исходного кода

fix(tests): update unit tests for API method changes

- camera.spec.ts: change listCameras and adminListCameras to POST
- machine.spec.ts: change listMachines to POST with wrapPageResponse
- camera/index.spec.ts: use listAllMachines with wrapArrayResponse

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
yb 2 недель назад
Родитель
Сommit
6134eeb4b5
3 измененных файлов с 29 добавлено и 21 удалено
  1. 18 10
      tests/unit/api/camera.spec.ts
  2. 5 5
      tests/unit/api/machine.spec.ts
  3. 6 6
      tests/unit/views/camera/index.spec.ts

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

@@ -28,22 +28,22 @@ describe('Camera API', () => {
 
 
   describe('Controller APIs', () => {
   describe('Controller APIs', () => {
     describe('listCameras', () => {
     describe('listCameras', () => {
-      it('should call GET /camera/list', async () => {
+      it('should call POST /camera/list', async () => {
         const mockResponse = wrapResponse(mockCameras)
         const mockResponse = wrapResponse(mockCameras)
-        vi.mocked(request.get).mockResolvedValue(mockResponse)
+        vi.mocked(request.post).mockResolvedValue(mockResponse)
 
 
         const result = await listCameras()
         const result = await listCameras()
 
 
-        expect(request.get).toHaveBeenCalledWith('/camera/list', undefined)
+        expect(request.post).toHaveBeenCalledWith('/camera/list', {})
         expect(result.data).toHaveLength(mockCameras.length)
         expect(result.data).toHaveLength(mockCameras.length)
       })
       })
 
 
       it('should call with machineId filter', async () => {
       it('should call with machineId filter', async () => {
-        vi.mocked(request.get).mockResolvedValue(wrapResponse([]))
+        vi.mocked(request.post).mockResolvedValue(wrapResponse([]))
 
 
         await listCameras('machine-001')
         await listCameras('machine-001')
 
 
-        expect(request.get).toHaveBeenCalledWith('/camera/list', { machineId: 'machine-001' })
+        expect(request.post).toHaveBeenCalledWith('/camera/list', { machineId: 'machine-001' })
       })
       })
     })
     })
 
 
@@ -116,14 +116,22 @@ describe('Camera API', () => {
 
 
   describe('Admin APIs', () => {
   describe('Admin APIs', () => {
     describe('adminListCameras', () => {
     describe('adminListCameras', () => {
-      it('should call GET /admin/cameras/list', async () => {
-        const mockResponse = wrapResponse(mockCameras)
-        vi.mocked(request.get).mockResolvedValue(mockResponse)
+      it('should call POST /admin/cameras/list', async () => {
+        const mockResponse = wrapResponse({
+          list: mockCameras,
+          total: mockCameras.length,
+          page: 1,
+          size: 20,
+          totalPages: 1,
+          hasNext: false,
+          hasPrevious: false
+        })
+        vi.mocked(request.post).mockResolvedValue(mockResponse)
 
 
         const result = await adminListCameras()
         const result = await adminListCameras()
 
 
-        expect(request.get).toHaveBeenCalledWith('/admin/cameras/list', undefined)
-        expect(result.data).toHaveLength(mockCameras.length)
+        expect(request.post).toHaveBeenCalledWith('/admin/cameras/list', {})
+        expect(result.data.list).toHaveLength(mockCameras.length)
       })
       })
     })
     })
 
 

+ 5 - 5
tests/unit/api/machine.spec.ts

@@ -1,7 +1,7 @@
 import { describe, it, expect, vi, beforeEach } from 'vitest'
 import { describe, it, expect, vi, beforeEach } from 'vitest'
 import { listMachines, getMachine, addMachine, updateMachine, deleteMachine } from '@/api/machine'
 import { listMachines, getMachine, addMachine, updateMachine, deleteMachine } from '@/api/machine'
 import * as request from '@/utils/request'
 import * as request from '@/utils/request'
-import { mockMachines, wrapResponse, wrapListResponse, wrapErrorResponse } from '../../fixtures'
+import { mockMachines, wrapResponse, wrapPageResponse, wrapErrorResponse } from '../../fixtures'
 
 
 vi.mock('@/utils/request', () => ({
 vi.mock('@/utils/request', () => ({
   get: vi.fn(),
   get: vi.fn(),
@@ -14,13 +14,13 @@ describe('Machine API', () => {
   })
   })
 
 
   describe('listMachines', () => {
   describe('listMachines', () => {
-    it('should call GET /admin/machines/list', async () => {
-      const mockResponse = wrapListResponse(mockMachines)
-      vi.mocked(request.get).mockResolvedValue(mockResponse)
+    it('should call POST /admin/machines/list', async () => {
+      const mockResponse = wrapPageResponse(mockMachines)
+      vi.mocked(request.post).mockResolvedValue(mockResponse)
 
 
       const result = await listMachines()
       const result = await listMachines()
 
 
-      expect(request.get).toHaveBeenCalledWith('/admin/machines/list', undefined)
+      expect(request.post).toHaveBeenCalledWith('/admin/machines/list', {})
       expect(result.success).toBe(true)
       expect(result.success).toBe(true)
       expect(result.data.list).toHaveLength(mockMachines.length)
       expect(result.data.list).toHaveLength(mockMachines.length)
       expect(result.data.list[0].machineId).toBe(mockMachines[0].machineId)
       expect(result.data.list[0].machineId).toBe(mockMachines[0].machineId)

+ 6 - 6
tests/unit/views/camera/index.spec.ts

@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
 import { mount, flushPromises } from '@vue/test-utils'
 import { mount, flushPromises } from '@vue/test-utils'
 import { createPinia, setActivePinia } from 'pinia'
 import { createPinia, setActivePinia } from 'pinia'
 import CameraView from '@/views/camera/index.vue'
 import CameraView from '@/views/camera/index.vue'
-import { wrapResponse, wrapListResponse, mockCameras, mockMachines } from '../../../fixtures'
+import { wrapResponse, wrapPageResponse, wrapArrayResponse, mockCameras, mockMachines } from '../../../fixtures'
 
 
 // Mock vue-router
 // Mock vue-router
 const mockPush = vi.fn()
 const mockPush = vi.fn()
@@ -40,17 +40,17 @@ vi.mock('@/api/camera', () => ({
 }))
 }))
 
 
 // Mock machine API
 // Mock machine API
-const mockListMachines = vi.fn()
+const mockListAllMachines = vi.fn()
 vi.mock('@/api/machine', () => ({
 vi.mock('@/api/machine', () => ({
-  listMachines: () => mockListMachines()
+  listAllMachines: () => mockListAllMachines()
 }))
 }))
 
 
 describe('Camera View', () => {
 describe('Camera View', () => {
   beforeEach(() => {
   beforeEach(() => {
     setActivePinia(createPinia())
     setActivePinia(createPinia())
     vi.clearAllMocks()
     vi.clearAllMocks()
-    mockAdminListCameras.mockResolvedValue(wrapListResponse(mockCameras))
-    mockListMachines.mockResolvedValue(wrapListResponse(mockMachines))
+    mockAdminListCameras.mockResolvedValue(wrapPageResponse(mockCameras))
+    mockListAllMachines.mockResolvedValue(wrapArrayResponse(mockMachines))
   })
   })
 
 
   const mountCamera = () => {
   const mountCamera = () => {
@@ -156,7 +156,7 @@ describe('Camera View', () => {
       mountCamera()
       mountCamera()
       await flushPromises()
       await flushPromises()
 
 
-      expect(mockListMachines).toHaveBeenCalled()
+      expect(mockListAllMachines).toHaveBeenCalled()
     })
     })
   })
   })