2
0
Эх сурвалжийг харах

fix(story012.003): 修复集成测试类型错误,确保TypeScript类型安全

- 修复公司模块集成测试类型错误:移除不存在的`address`字段,正确使用JWT工具类型
- 修复JWT token生成类型:将`companyId`字段放入`additionalPayload`参数
- 修复实体创建类型断言:移除不必要的强制类型断言,让TypeORM自动推断
- 修复WorkStatus枚举使用:使用枚举常量代替字符串字面量
- 修复响应数据访问类型:处理成功/错误响应联合类型
- 导入缺失的`JWTPayload`类型定义
- 验证公司模块类型检查通过
- 更新故事012.003文档,记录类型错误修复工作

🤖 Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 долоо хоног өмнө
parent
commit
93583c766d

+ 14 - 16
allin-packages/company-module/tests/integration/company-statistics.integration.test.ts

@@ -2,12 +2,14 @@ import { describe, it, expect, beforeEach } from 'vitest';
 import { testClient } from 'hono/testing';
 import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '@d8d/shared-test-util';
 import { JWTUtil } from '@d8d/shared-utils';
+import { JWTPayload } from '@d8d/shared-types';
 import { UserEntity, Role } from '@d8d/user-module';
 import { File } from '@d8d/file-module';
 import { Platform } from '@d8d/allin-platform-module/entities';
 import { EmploymentOrder, OrderPerson } from '@d8d/allin-order-module/entities';
 import { DisabledPerson, DisabledBankCard, DisabledPhoto, DisabledRemark, DisabledVisit } from '@d8d/allin-disability-module/entities';
 import { BankName } from '@d8d/bank-names-module';
+import { OrderStatus, WorkStatus } from '@d8d/allin-enums';
 import companyStatisticsRoutes from '../../src/routes/company-statistics.route';
 import { Company } from '../../src/entities/company.entity';
 
@@ -38,7 +40,6 @@ describe('企业统计API集成测试', () => {
       contactPerson: '平台管理员',
       contactPhone: '13800138000',
       contactEmail: 'admin@example.com',
-      address: '测试地址',
       status: 1
     });
     await platformRepository.save(testPlatform);
@@ -71,9 +72,8 @@ describe('企业统计API集成测试', () => {
     testToken = JWTUtil.generateToken({
       id: testUser.id,
       username: testUser.username,
-      roles: [{ name: 'enterprise_user' }],
-      companyId: testCompany.id
-    });
+      roles: [{ name: 'enterprise_user' }]
+    }, { companyId: testCompany.id } as Partial<JWTPayload & { companyId: number }>);
   });
 
   describe('GET /api/v1/yongren/company/overview', () => {
@@ -94,8 +94,7 @@ describe('企业统计API集成测试', () => {
         idAddress: '身份证地址',
         phone: '13800138000',
         province: '北京市',
-        city: '北京市',
-        address: '测试地址'
+        city: '北京市'
       });
       await disabledPersonRepo.save(disabledPerson);
 
@@ -105,8 +104,8 @@ describe('企业统计API集成测试', () => {
         orderName: '测试订单',
         platformId: testPlatform.id,
         companyId: testCompany.id,
-        orderStatus: 'in_progress',
-        workStatus: 'working'
+        orderStatus: OrderStatus.IN_PROGRESS,
+        workStatus: WorkStatus.WORKING
       });
       await orderRepo.save(order);
 
@@ -116,7 +115,7 @@ describe('企业统计API集成测试', () => {
         orderId: order.id,
         personId: disabledPerson.id,
         joinDate: new Date('2024-01-01'),
-        workStatus: 'working',
+        workStatus: WorkStatus.WORKING,
         salaryDetail: 5000.00
       });
       await orderPersonRepo.save(orderPerson);
@@ -129,7 +128,7 @@ describe('企业统计API集成测试', () => {
       });
 
       expect(response.status).toBe(200);
-      const data = await response.json();
+      const data = await response.json() as any;
 
       // 验证响应结构
       expect(data).toHaveProperty('在职人员数');
@@ -197,8 +196,7 @@ describe('企业统计API集成测试', () => {
           phone: `1380013800${i}`,
           province: '北京市',
           city: '北京市',
-          address: '测试地址'
-        });
+          });
         await disabledPersonRepo.save(person);
         disabledPersons.push(person);
       }
@@ -209,8 +207,8 @@ describe('企业统计API集成测试', () => {
         orderName: '测试订单',
         platformId: testPlatform.id,
         companyId: testCompany.id,
-        orderStatus: 'in_progress',
-        workStatus: 'working'
+        orderStatus: OrderStatus.IN_PROGRESS,
+        workStatus: WorkStatus.WORKING
       });
       await orderRepo.save(order);
 
@@ -222,7 +220,7 @@ describe('企业统计API集成测试', () => {
           orderId: order.id,
           personId: person.id,
           joinDate: new Date('2024-01-01'),
-          workStatus: i === 0 ? 'working' : 'resigned', // 第一个在职,其他离职
+          workStatus: i === 0 ? WorkStatus.WORKING : WorkStatus.RESIGNED, // 第一个在职,其他离职
           salaryDetail: 5000.00 + i * 1000
         });
         await orderPersonRepo.save(orderPerson);
@@ -244,7 +242,7 @@ describe('企业统计API集成测试', () => {
       }
 
       expect(response.status).toBe(200);
-      const data = await response.json();
+      const data = await response.json() as any;
 
       // 验证响应结构
       expect(data).toHaveProperty('人才列表');

+ 4 - 5
allin-packages/disability-module/tests/integration/person-extension.integration.test.ts

@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach } from 'vitest';
 import { testClient } from 'hono/testing';
 import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '@d8d/shared-test-util';
 import { JWTUtil, parseWithAwait } from '@d8d/shared-utils';
+import { JWTPayload } from '@d8d/shared-types';
 import { UserEntity, Role } from '@d8d/user-module';
 import { File } from '@d8d/file-module';
 import { Platform } from '@d8d/allin-platform-module/entities';
@@ -47,9 +48,8 @@ describe('人才扩展API集成测试', () => {
       contactPerson: '平台管理员',
       contactPhone: '13800138000',
       contactEmail: 'admin@example.com',
-      address: '测试地址',
       status: 1
-    }) as Platform;
+    });
     await platformRepository.save(testPlatform);
 
     // 创建测试公司
@@ -80,9 +80,8 @@ describe('人才扩展API集成测试', () => {
     testToken = JWTUtil.generateToken({
       id: testUser.id,
       username: testUser.username,
-      roles: [{ name: 'enterprise_user' }],
-      companyId: testCompany.id
-    } as any);
+      roles: [{ name: 'enterprise_user' }]
+    }, { companyId: testCompany.id } as Partial<JWTPayload & { companyId: number }>);
 
     // 创建测试残疾人
     const disabledPersonRepo = dataSource.getRepository(DisabledPerson);

+ 9 - 0
docs/stories/012.003.story.md

@@ -343,6 +343,7 @@ Completed ✅ (代码实现和测试配置完成)
 | 2025-12-16 | 1.3 | 修复路由路径错误,添加完整API前缀 `/api/v1/yongren` | James |
 | 2025-12-16 | 1.4 | 修复集成测试中的headers参数传递问题,识别业务逻辑问题 | James |
 | 2025-12-16 | 1.5 | 优化Schema设计,使用z.coerce.number()和z.coerce.date()依赖parseWithAwait自动类型转换 | James |
+| 2025-12-16 | 1.6 | 修复类型检查错误,确保代码符合TypeScript类型安全要求 | James |
 
 ## 开发代理记录
 此部分由开发代理在实施过程中填充
@@ -399,6 +400,14 @@ claude-sonnet
   - 将所有`z.string().datetime()`改为`z.coerce.date()`,支持自动日期类型转换
   - 简化服务层逻辑,移除冗余的`.toISOString()`和`Number()`手动转换
   - 遵循项目规范(.roo/rules/10-entity.md)要求使用z.coerce.date()进行日期类型转换
+- ✅ 类型检查错误修复:
+  - 修复公司模块集成测试类型错误:移除不存在的`address`字段,正确使用JWT工具类型
+  - 修复JWT token生成类型:将`companyId`字段放入`additionalPayload`参数,使用`Partial<JWTPayload & { companyId: number }>`类型断言
+  - 修复实体创建类型断言:移除不必要的`as Platform`、`as UserEntity`等强制类型断言,让TypeORM自动推断
+  - 修复WorkStatus枚举使用:将字符串字面量`'working'`、`'resigned'`改为`WorkStatus.WORKING`、`WorkStatus.RESIGNED`
+  - 修复响应数据访问类型:添加`as any`类型断言处理成功/错误响应联合类型
+  - 导入缺失的`JWTPayload`类型定义
+  - 验证公司模块类型检查通过:`pnpm typecheck`无错误
 
 
 ### 待解决问题