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

✅ test(salary): 更新薪资集成测试以适配新的 API 客户端结构

- 重构模拟的 `salaryClient`,将 `$get` 方法移至 `list` 对象下以匹配新的 API 结构
- 更新测试断言,将 `mockClient.$get` 的调用检查改为 `mockClient.list.$get`
- 更新模拟 API 错误的代码,将 `mockClient.$get.mockRejectedValueOnce` 改为 `(mockClient.list.$get as any).mockRejectedValueOnce`
yourname 1 месяц назад
Родитель
Сommit
692f88d821

+ 39 - 37
allin-packages/salary-management-ui/tests/integration/salary.integration.test.tsx

@@ -55,41 +55,43 @@ const createMockResponse = (status: number, data?: any) => ({
 // Mock API client
 vi.mock('../../src/api/salaryClient', () => {
   const mockSalaryClient = {
-    $get: vi.fn(() => Promise.resolve(createMockResponse(200, {
-      data: [
-        {
-          id: 1,
-          provinceId: 110000,
-          cityId: 110100,
-          districtId: null,
-          basicSalary: 5000.00,
-          allowance: 1000.00,
-          insurance: 500.00,
-          housingFund: 800.00,
-          totalSalary: 4700.00,
-          updateTime: '2024-01-01T00:00:00Z',
-          province: { id: 110000, name: '北京市' },
-          city: { id: 110100, name: '北京市辖区' },
-          district: null
-        },
-        {
-          id: 2,
-          provinceId: 310000,
-          cityId: 310100,
-          districtId: 310101,
-          basicSalary: 6000.00,
-          allowance: 1200.00,
-          insurance: 600.00,
-          housingFund: 900.00,
-          totalSalary: 5700.00,
-          updateTime: '2024-01-02T00:00:00Z',
-          province: { id: 310000, name: '上海市' },
-          city: { id: 310100, name: '上海市辖区' },
-          district: { id: 310101, name: '黄浦区' }
-        }
-      ],
-      total: 2
-    }))),
+    list: {
+      $get: vi.fn(() => Promise.resolve(createMockResponse(200, {
+        data: [
+          {
+            id: 1,
+            provinceId: 110000,
+            cityId: 110100,
+            districtId: null,
+            basicSalary: 5000.00,
+            allowance: 1000.00,
+            insurance: 500.00,
+            housingFund: 800.00,
+            totalSalary: 4700.00,
+            updateTime: '2024-01-01T00:00:00Z',
+            province: { id: 110000, name: '北京市' },
+            city: { id: 110100, name: '北京市辖区' },
+            district: null
+          },
+          {
+            id: 2,
+            provinceId: 310000,
+            cityId: 310100,
+            districtId: 310101,
+            basicSalary: 6000.00,
+            allowance: 1200.00,
+            insurance: 600.00,
+            housingFund: 900.00,
+            totalSalary: 5700.00,
+            updateTime: '2024-01-02T00:00:00Z',
+            province: { id: 310000, name: '上海市' },
+            city: { id: 310100, name: '上海市辖区' },
+            district: { id: 310101, name: '黄浦区' }
+          }
+        ],
+        total: 2
+      })))
+    },
     create: {
       $post: vi.fn(() => Promise.resolve(createMockResponse(200, {
         id: 3,
@@ -254,7 +256,7 @@ describe('薪资管理集成测试', () => {
     // 验证API调用
     await waitFor(() => {
       const mockClient = salaryClientManager.get();
-      expect(mockClient.$get).toHaveBeenCalledWith({
+      expect(mockClient.list.$get).toHaveBeenCalledWith({
         query: {
           skip: 0,
           take: 10,
@@ -354,7 +356,7 @@ describe('薪资管理集成测试', () => {
   it('应该处理API错误', async () => {
     // Mock API错误
     const mockClient = salaryClientManager.get();
-    mockClient.$get.mockRejectedValueOnce(new Error('获取薪资列表失败'));
+    (mockClient.list.$get as any).mockRejectedValueOnce(new Error('获取薪资列表失败'));
 
     renderComponent();