|
@@ -375,4 +375,248 @@ describe('人才扩展API集成测试', () => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ describe('GET /api/v1/yongren/disability-person (企业专用人才列表)', () => {
|
|
|
|
|
+ it('应该返回企业人才列表', async () => {
|
|
|
|
|
+ console.debug('测试token:', testToken);
|
|
|
|
|
+ console.debug('测试用户companyId:', testUser.companyId);
|
|
|
|
|
+ console.debug('测试公司ID:', testCompany.id);
|
|
|
|
|
+
|
|
|
|
|
+ const response = await client.$get({
|
|
|
|
|
+ query: {
|
|
|
|
|
+ page: '1',
|
|
|
|
|
+ limit: '10'
|
|
|
|
|
+ }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ console.debug('响应状态:', response.status);
|
|
|
|
|
+ if (response.status !== 200) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const errorData = await response.json();
|
|
|
|
|
+ console.debug('错误响应:', errorData);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.debug('无法解析错误响应:', e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(200);
|
|
|
|
|
+ const data = await response.json() as { data: any[], pagination: any };
|
|
|
|
|
+
|
|
|
|
|
+ // 验证响应结构
|
|
|
|
|
+ expect(data).toHaveProperty('data');
|
|
|
|
|
+ expect(data).toHaveProperty('pagination');
|
|
|
|
|
+ expect(Array.isArray(data.data)).toBe(true);
|
|
|
|
|
+ expect(data.pagination).toHaveProperty('page');
|
|
|
|
|
+ expect(data.pagination).toHaveProperty('limit');
|
|
|
|
|
+ expect(data.pagination).toHaveProperty('total');
|
|
|
|
|
+ expect(data.pagination).toHaveProperty('totalPages');
|
|
|
|
|
+
|
|
|
|
|
+ // 应该至少包含我们创建的人员
|
|
|
|
|
+ if (data.data.length > 0) {
|
|
|
|
|
+ const person = data.data[0];
|
|
|
|
|
+ expect(person).toHaveProperty('personId');
|
|
|
|
|
+ expect(person).toHaveProperty('name');
|
|
|
|
|
+ expect(person).toHaveProperty('gender');
|
|
|
|
|
+ expect(person).toHaveProperty('idCard');
|
|
|
|
|
+ expect(person).toHaveProperty('disabilityType');
|
|
|
|
|
+ expect(person).toHaveProperty('disabilityLevel');
|
|
|
|
|
+ expect(person).toHaveProperty('phone');
|
|
|
|
|
+ expect(person).toHaveProperty('jobStatus');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('应该支持搜索功能', async () => {
|
|
|
|
|
+ const response = await client.$get({
|
|
|
|
|
+ query: {
|
|
|
|
|
+ search: '测试残疾人',
|
|
|
|
|
+ page: '1',
|
|
|
|
|
+ limit: '10'
|
|
|
|
|
+ }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(200);
|
|
|
|
|
+ const data = await response.json() as { data: any[], pagination: any };
|
|
|
|
|
+ expect(data.data.length).toBeGreaterThan(0);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('应该支持残疾类型筛选', async () => {
|
|
|
|
|
+ const response = await client.$get({
|
|
|
|
|
+ query: {
|
|
|
|
|
+ disabilityType: '视力残疾',
|
|
|
|
|
+ page: '1',
|
|
|
|
|
+ limit: '10'
|
|
|
|
|
+ }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(200);
|
|
|
|
|
+ const data = await response.json() as { data: any[], pagination: any };
|
|
|
|
|
+ // 可能匹配我们创建的人员
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('应该支持分页', async () => {
|
|
|
|
|
+ const response = await client.$get({
|
|
|
|
|
+ query: {
|
|
|
|
|
+ page: '1',
|
|
|
|
|
+ limit: '5'
|
|
|
|
|
+ }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(200);
|
|
|
|
|
+ const data = await response.json() as { data: any[], pagination: any };
|
|
|
|
|
+ expect(data.pagination.limit).toBe(5);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('其他企业用户不应该看到数据', async () => {
|
|
|
|
|
+ // 创建另一个企业的用户
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+ const companyRepository = dataSource.getRepository(Company);
|
|
|
|
|
+ const otherCompany = companyRepository.create({
|
|
|
|
|
+ companyName: `其他公司_${Date.now()}_2`,
|
|
|
|
|
+ contactPerson: '其他联系人2',
|
|
|
|
|
+ contactPhone: '13900139002',
|
|
|
|
|
+ contactEmail: 'other2@example.com',
|
|
|
|
|
+ address: '其他地址2',
|
|
|
|
|
+ platformId: testPlatform.id,
|
|
|
|
|
+ status: 1
|
|
|
|
|
+ });
|
|
|
|
|
+ await companyRepository.save(otherCompany);
|
|
|
|
|
+
|
|
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
|
|
+ const otherUser = userRepository.create({
|
|
|
|
|
+ username: `other_enterprise_user_${Date.now()}`,
|
|
|
|
|
+ password: 'test_password',
|
|
|
|
|
+ nickname: '其他企业用户',
|
|
|
|
|
+ registrationSource: 'web',
|
|
|
|
|
+ companyId: otherCompany.id
|
|
|
|
|
+ });
|
|
|
|
|
+ await userRepository.save(otherUser);
|
|
|
|
|
+
|
|
|
|
|
+ // 生成其他企业用户的token
|
|
|
|
|
+ const otherToken = JWTUtil.generateToken({
|
|
|
|
|
+ id: otherUser.id,
|
|
|
|
|
+ username: otherUser.username,
|
|
|
|
|
+ roles: [{ name: 'enterprise_user' }]
|
|
|
|
|
+ }, { companyId: otherCompany.id } as Partial<JWTPayload & { companyId: number }>);
|
|
|
|
|
+
|
|
|
|
|
+ // 其他企业用户应该看不到任何数据(因为人员不属于他的企业)
|
|
|
|
|
+ const response = await client.$get({
|
|
|
|
|
+ query: {
|
|
|
|
|
+ page: '1',
|
|
|
|
|
+ limit: '10'
|
|
|
|
|
+ }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: { Authorization: `Bearer ${otherToken}` }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(200);
|
|
|
|
|
+ const data = await response.json() as { data: any[], pagination: any };
|
|
|
|
|
+ // 可能返回空数组,因为人员不属于其他企业
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ describe('GET /api/v1/yongren/disability-person/{id} (企业专用人才详情)', () => {
|
|
|
|
|
+ it('应该返回企业人才详情', async () => {
|
|
|
|
|
+ const response = await client[':id'].$get({
|
|
|
|
|
+ param: { id: testDisabledPerson.id }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(200);
|
|
|
|
|
+ const data = await response.json() as any;
|
|
|
|
|
+
|
|
|
|
|
+ // 验证响应结构
|
|
|
|
|
+ expect(data).toHaveProperty('personId');
|
|
|
|
|
+ expect(data).toHaveProperty('name');
|
|
|
|
|
+ expect(data).toHaveProperty('gender');
|
|
|
|
|
+ expect(data).toHaveProperty('idCard');
|
|
|
|
|
+ expect(data).toHaveProperty('disabilityType');
|
|
|
|
|
+ expect(data).toHaveProperty('disabilityLevel');
|
|
|
|
|
+ expect(data).toHaveProperty('birthDate');
|
|
|
|
|
+ expect(data).toHaveProperty('phone');
|
|
|
|
|
+ expect(data).toHaveProperty('jobStatus');
|
|
|
|
|
+ expect(data).toHaveProperty('bankCards');
|
|
|
|
|
+ expect(data).toHaveProperty('photos');
|
|
|
|
|
+ expect(Array.isArray(data.bankCards)).toBe(true);
|
|
|
|
|
+ expect(Array.isArray(data.photos)).toBe(true);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('访问其他企业人员应该返回404', async () => {
|
|
|
|
|
+ // 创建另一个公司的残疾人
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+
|
|
|
|
|
+ // 创建另一个公司
|
|
|
|
|
+ const companyRepository = dataSource.getRepository(Company);
|
|
|
|
|
+ const otherCompany = companyRepository.create({
|
|
|
|
|
+ companyName: `其他公司_${Date.now()}_3`,
|
|
|
|
|
+ contactPerson: '其他联系人3',
|
|
|
|
|
+ contactPhone: '13900139003',
|
|
|
|
|
+ contactEmail: 'other3@example.com',
|
|
|
|
|
+ address: '其他地址3',
|
|
|
|
|
+ platformId: testPlatform.id,
|
|
|
|
|
+ status: 1
|
|
|
|
|
+ });
|
|
|
|
|
+ await companyRepository.save(otherCompany);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建另一个公司的残疾人(但不关联到当前企业)
|
|
|
|
|
+ const disabledPersonRepo = dataSource.getRepository(DisabledPerson);
|
|
|
|
|
+ const otherDisabledPerson = disabledPersonRepo.create({
|
|
|
|
|
+ name: '其他公司残疾人详情测试',
|
|
|
|
|
+ idCard: `110101${Date.now() % 100000000 + 2000}`,
|
|
|
|
|
+ gender: '女',
|
|
|
|
|
+ birthDate: new Date('1995-01-01'),
|
|
|
|
|
+ disabilityType: '听力残疾',
|
|
|
|
|
+ disabilityLevel: '二级',
|
|
|
|
|
+ disabilityId: `DIS${Date.now() % 100000000 + 2000}`,
|
|
|
|
|
+ idAddress: '其他地址',
|
|
|
|
|
+ phone: '13900139003',
|
|
|
|
|
+ province: '上海市',
|
|
|
|
|
+ city: '上海市',
|
|
|
|
|
+ detailedAddress: '其他地址'
|
|
|
|
|
+ });
|
|
|
|
|
+ await disabledPersonRepo.save(otherDisabledPerson);
|
|
|
|
|
+
|
|
|
|
|
+ // 尝试访问其他公司人员数据
|
|
|
|
|
+ const response = await client[':id'].$get({
|
|
|
|
|
+ param: { id: otherDisabledPerson.id }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(404);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('访问不存在的人员应该返回404', async () => {
|
|
|
|
|
+ const nonExistentId = 999999;
|
|
|
|
|
+ const response = await client[':id'].$get({
|
|
|
|
|
+ param: { id: nonExistentId }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${testToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(404);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|