|
|
@@ -0,0 +1,339 @@
|
|
|
+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 { UserEntity, Role } from '@d8d/user-module';
|
|
|
+import { File } from '@d8d/file-module';
|
|
|
+import { Platform } from '@d8d/allin-platform-module/entities';
|
|
|
+import { EmploymentOrder, OrderPerson, OrderPersonAsset } from '@d8d/allin-order-module/entities';
|
|
|
+import { DisabledPerson, DisabledBankCard } from '../../src/entities';
|
|
|
+import personExtensionRoutes from '../../src/routes/person-extension.route';
|
|
|
+import { Company } from '@d8d/allin-company-module/entities';
|
|
|
+
|
|
|
+// 设置集成测试钩子 - 需要包含所有相关实体
|
|
|
+setupIntegrationDatabaseHooksWithEntities([
|
|
|
+ UserEntity, File, Role, Platform, Company,
|
|
|
+ EmploymentOrder, OrderPerson, OrderPersonAsset,
|
|
|
+ DisabledPerson, DisabledBankCard
|
|
|
+])
|
|
|
+
|
|
|
+describe('人才扩展API集成测试', () => {
|
|
|
+ let client: ReturnType<typeof testClient<typeof personExtensionRoutes>>;
|
|
|
+ let testToken: string;
|
|
|
+ let testUser: UserEntity;
|
|
|
+ let testCompany: Company;
|
|
|
+ let testPlatform: Platform;
|
|
|
+ let testDisabledPerson: DisabledPerson;
|
|
|
+ let testOrder: EmploymentOrder;
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ // 创建测试客户端
|
|
|
+ client = testClient(personExtensionRoutes);
|
|
|
+
|
|
|
+ // 获取数据源
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+
|
|
|
+ // 创建测试平台
|
|
|
+ const platformRepository = dataSource.getRepository(Platform);
|
|
|
+ testPlatform = platformRepository.create({
|
|
|
+ platformName: `测试平台_${Date.now()}`,
|
|
|
+ contactPerson: '平台管理员',
|
|
|
+ contactPhone: '13800138000',
|
|
|
+ contactEmail: 'admin@example.com',
|
|
|
+ address: '测试地址',
|
|
|
+ status: 1
|
|
|
+ });
|
|
|
+ await platformRepository.save(testPlatform);
|
|
|
+
|
|
|
+ // 创建测试公司
|
|
|
+ const companyRepository = dataSource.getRepository(Company);
|
|
|
+ testCompany = companyRepository.create({
|
|
|
+ companyName: `测试公司_${Date.now()}`,
|
|
|
+ contactPerson: '公司联系人',
|
|
|
+ contactPhone: '13900139000',
|
|
|
+ contactEmail: 'company@example.com',
|
|
|
+ address: '公司地址',
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ status: 1
|
|
|
+ });
|
|
|
+ await companyRepository.save(testCompany);
|
|
|
+
|
|
|
+ // 创建测试企业用户
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
+ testUser = userRepository.create({
|
|
|
+ username: `enterprise_user_${Date.now()}`,
|
|
|
+ password: 'test_password',
|
|
|
+ nickname: '企业测试用户',
|
|
|
+ registrationSource: 'web',
|
|
|
+ companyId: testCompany.id
|
|
|
+ });
|
|
|
+ await userRepository.save(testUser);
|
|
|
+
|
|
|
+ // 生成测试用户的token
|
|
|
+ testToken = JWTUtil.generateToken({
|
|
|
+ id: testUser.id,
|
|
|
+ username: testUser.username,
|
|
|
+ roles: [{ name: 'enterprise_user' }],
|
|
|
+ companyId: testCompany.id
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建测试残疾人
|
|
|
+ const disabledPersonRepo = dataSource.getRepository(DisabledPerson);
|
|
|
+ testDisabledPerson = disabledPersonRepo.create({
|
|
|
+ name: '测试残疾人',
|
|
|
+ idCard: `110101${Date.now() % 100000000}`,
|
|
|
+ gender: 1,
|
|
|
+ birthDate: new Date('1990-01-01'),
|
|
|
+ disabilityType: '视力残疾',
|
|
|
+ disabilityLevel: '一级',
|
|
|
+ address: '测试地址'
|
|
|
+ });
|
|
|
+ await disabledPersonRepo.save(testDisabledPerson);
|
|
|
+
|
|
|
+ // 创建测试订单
|
|
|
+ const orderRepo = dataSource.getRepository(EmploymentOrder);
|
|
|
+ testOrder = orderRepo.create({
|
|
|
+ orderName: '测试订单',
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ companyId: testCompany.id,
|
|
|
+ orderStatus: 'confirmed',
|
|
|
+ workStatus: 'working'
|
|
|
+ });
|
|
|
+ await orderRepo.save(testOrder);
|
|
|
+
|
|
|
+ // 创建订单人员关联,使人员属于该企业
|
|
|
+ const orderPersonRepo = dataSource.getRepository(OrderPerson);
|
|
|
+ const orderPerson = orderPersonRepo.create({
|
|
|
+ orderId: testOrder.id,
|
|
|
+ personId: testDisabledPerson.id,
|
|
|
+ joinDate: new Date('2024-01-01'),
|
|
|
+ workStatus: 'working',
|
|
|
+ salaryDetail: 5000.00
|
|
|
+ });
|
|
|
+ await orderPersonRepo.save(orderPerson);
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('GET /api/v1/yongren/disability-person/{id}/work-history', () => {
|
|
|
+ it('应该返回人员工作历史', async () => {
|
|
|
+ // 准备测试数据:多个订单关联
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const orderPersonRepo = dataSource.getRepository(OrderPerson);
|
|
|
+
|
|
|
+ // 创建另一个订单关联
|
|
|
+ const orderRepo = dataSource.getRepository(EmploymentOrder);
|
|
|
+ const anotherOrder = orderRepo.create({
|
|
|
+ orderName: '另一个测试订单',
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ companyId: testCompany.id,
|
|
|
+ orderStatus: 'completed',
|
|
|
+ workStatus: 'working'
|
|
|
+ });
|
|
|
+ await orderRepo.save(anotherOrder);
|
|
|
+
|
|
|
+ const anotherOrderPerson = orderPersonRepo.create({
|
|
|
+ orderId: anotherOrder.id,
|
|
|
+ personId: testDisabledPerson.id,
|
|
|
+ joinDate: new Date('2024-06-01'),
|
|
|
+ actualStartDate: new Date('2024-06-02'),
|
|
|
+ leaveDate: new Date('2024-12-31'),
|
|
|
+ workStatus: 'resigned',
|
|
|
+ salaryDetail: 6000.00
|
|
|
+ });
|
|
|
+ await orderPersonRepo.save(anotherOrderPerson);
|
|
|
+
|
|
|
+ // 调用API
|
|
|
+ const response = await client.api.v1.yongren.disabilityPerson[':id'].workHistory.$get({
|
|
|
+ param: { id: testDisabledPerson.id },
|
|
|
+ header: {
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+ const data = await response.json();
|
|
|
+
|
|
|
+ // 验证响应结构
|
|
|
+ expect(data).toHaveProperty('工作历史');
|
|
|
+ expect(Array.isArray(data.工作历史)).toBe(true);
|
|
|
+
|
|
|
+ // 验证数据
|
|
|
+ expect(data.工作历史.length).toBeGreaterThanOrEqual(1);
|
|
|
+ const workHistory = data.工作历史[0];
|
|
|
+ expect(workHistory).toHaveProperty('订单ID');
|
|
|
+ expect(workHistory).toHaveProperty('订单名称');
|
|
|
+ expect(workHistory).toHaveProperty('入职日期');
|
|
|
+ expect(workHistory).toHaveProperty('工作状态');
|
|
|
+ expect(workHistory).toHaveProperty('个人薪资');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('访问其他企业人员应该返回403', async () => {
|
|
|
+ // 创建另一个公司的残疾人
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+
|
|
|
+ // 创建另一个公司
|
|
|
+ const companyRepository = dataSource.getRepository(Company);
|
|
|
+ const otherCompany = companyRepository.create({
|
|
|
+ companyName: `其他公司_${Date.now()}`,
|
|
|
+ contactPerson: '其他联系人',
|
|
|
+ contactPhone: '13900139001',
|
|
|
+ contactEmail: 'other@example.com',
|
|
|
+ address: '其他地址',
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ status: 1
|
|
|
+ });
|
|
|
+ await companyRepository.save(otherCompany);
|
|
|
+
|
|
|
+ // 创建另一个公司的残疾人
|
|
|
+ const disabledPersonRepo = dataSource.getRepository(DisabledPerson);
|
|
|
+ const otherDisabledPerson = disabledPersonRepo.create({
|
|
|
+ name: '其他公司残疾人',
|
|
|
+ idCard: `110101${Date.now() % 100000000 + 1000}`,
|
|
|
+ gender: 2,
|
|
|
+ birthDate: new Date('1995-01-01'),
|
|
|
+ disabilityType: '听力残疾',
|
|
|
+ disabilityLevel: '二级',
|
|
|
+ address: '其他地址'
|
|
|
+ });
|
|
|
+ await disabledPersonRepo.save(otherDisabledPerson);
|
|
|
+
|
|
|
+ // 尝试访问其他公司人员数据
|
|
|
+ const response = await client.api.v1.yongren.disabilityPerson[':id'].workHistory.$get({
|
|
|
+ param: { id: otherDisabledPerson.id },
|
|
|
+ header: {
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(403);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('GET /api/v1/yongren/disability-person/{id}/salary-history', () => {
|
|
|
+ it('应该返回人员薪资历史', async () => {
|
|
|
+ // 注意:薪资历史可能需要从薪资模块获取,这里暂时返回空数组
|
|
|
+ const response = await client.api.v1.yongren.disabilityPerson[':id'].salaryHistory.$get({
|
|
|
+ param: { id: testDisabledPerson.id },
|
|
|
+ header: {
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+ const data = await response.json();
|
|
|
+
|
|
|
+ // 验证响应结构
|
|
|
+ expect(data).toHaveProperty('薪资历史');
|
|
|
+ expect(Array.isArray(data.薪资历史)).toBe(true);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('GET /api/v1/yongren/disability-person/{id}/credit-info', () => {
|
|
|
+ it('应该返回人员征信信息', async () => {
|
|
|
+ // 准备测试数据:银行卡信息
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+
|
|
|
+ // 创建文件
|
|
|
+ const fileRepository = dataSource.getRepository(File);
|
|
|
+ const testFile = fileRepository.create({
|
|
|
+ name: '银行卡照片.jpg',
|
|
|
+ type: 'image/jpeg',
|
|
|
+ size: 1024,
|
|
|
+ path: 'uploads/bank-card.jpg',
|
|
|
+ description: '银行卡照片',
|
|
|
+ uploadUserId: testUser.id,
|
|
|
+ uploadTime: new Date()
|
|
|
+ });
|
|
|
+ await fileRepository.save(testFile);
|
|
|
+
|
|
|
+ // 创建银行卡记录
|
|
|
+ const bankCardRepo = dataSource.getRepository(DisabledBankCard);
|
|
|
+ const bankCard = bankCardRepo.create({
|
|
|
+ personId: testDisabledPerson.id,
|
|
|
+ subBankName: '测试支行',
|
|
|
+ bankNameId: 1, // 假设银行ID为1
|
|
|
+ cardNumber: '6228481234567890123',
|
|
|
+ cardholderName: '测试持卡人',
|
|
|
+ cardType: '一类卡',
|
|
|
+ fileId: testFile.id,
|
|
|
+ isDefault: 1
|
|
|
+ });
|
|
|
+ await bankCardRepo.save(bankCard);
|
|
|
+
|
|
|
+ // 调用API
|
|
|
+ const response = await client.api.v1.yongren.disabilityPerson[':id'].creditInfo.$get({
|
|
|
+ param: { id: testDisabledPerson.id },
|
|
|
+ header: {
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+ const data = await response.json();
|
|
|
+
|
|
|
+ // 验证响应结构
|
|
|
+ expect(data).toHaveProperty('征信信息');
|
|
|
+ expect(Array.isArray(data.征信信息)).toBe(true);
|
|
|
+
|
|
|
+ if (data.征信信息.length > 0) {
|
|
|
+ const creditInfo = data.征信信息[0];
|
|
|
+ expect(creditInfo).toHaveProperty('文件ID');
|
|
|
+ expect(creditInfo).toHaveProperty('银行卡号');
|
|
|
+ expect(creditInfo).toHaveProperty('持卡人姓名');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('GET /api/v1/yongren/disability-person/{id}/videos', () => {
|
|
|
+ it('应该返回人员视频关联', async () => {
|
|
|
+ // 准备测试数据:订单人员资产(视频)
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+
|
|
|
+ // 创建文件
|
|
|
+ const fileRepository = dataSource.getRepository(File);
|
|
|
+ const testFile = fileRepository.create({
|
|
|
+ name: '工作视频.mp4',
|
|
|
+ type: 'video/mp4',
|
|
|
+ size: 1024000,
|
|
|
+ path: 'uploads/work-video.mp4',
|
|
|
+ description: '工作视频',
|
|
|
+ uploadUserId: testUser.id,
|
|
|
+ uploadTime: new Date()
|
|
|
+ });
|
|
|
+ await fileRepository.save(testFile);
|
|
|
+
|
|
|
+ // 创建订单人员资产记录
|
|
|
+ const assetRepo = dataSource.getRepository(OrderPersonAsset);
|
|
|
+ const asset = assetRepo.create({
|
|
|
+ orderId: testOrder.id,
|
|
|
+ personId: testDisabledPerson.id,
|
|
|
+ assetType: 'work_video',
|
|
|
+ assetFileType: 'video',
|
|
|
+ fileId: testFile.id,
|
|
|
+ relatedTime: new Date()
|
|
|
+ });
|
|
|
+ await assetRepo.save(asset);
|
|
|
+
|
|
|
+ // 调用API
|
|
|
+ const response = await client.api.v1.yongren.disabilityPerson[':id'].videos.$get({
|
|
|
+ param: { id: testDisabledPerson.id },
|
|
|
+ header: {
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+ const data = await response.json();
|
|
|
+
|
|
|
+ // 验证响应结构
|
|
|
+ expect(data).toHaveProperty('视频列表');
|
|
|
+ expect(Array.isArray(data.视频列表)).toBe(true);
|
|
|
+
|
|
|
+ if (data.视频列表.length > 0) {
|
|
|
+ const video = data.视频列表[0];
|
|
|
+ expect(video).toHaveProperty('视频类型');
|
|
|
+ expect(video).toHaveProperty('文件ID');
|
|
|
+ expect(video).toHaveProperty('关联订单ID');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|