| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571 |
- 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 { BankName } from '@d8d/bank-names-module';
- import disabledPersonRoutes from '../../src/routes/disabled-person.routes';
- import { DisabledPerson } from '../../src/entities/disabled-person.entity';
- import { DisabledBankCard } from '../../src/entities/disabled-bank-card.entity';
- import { DisabledPhoto } from '../../src/entities/disabled-photo.entity';
- import { DisabledRemark } from '../../src/entities/disabled-remark.entity';
- import { DisabledVisit } from '../../src/entities/disabled-visit.entity';
- // 设置集成测试钩子 - 包含所有相关实体
- setupIntegrationDatabaseHooksWithEntities([
- UserEntity,
- Role,
- File,
- BankName,
- DisabledPerson,
- DisabledBankCard,
- DisabledPhoto,
- DisabledRemark,
- DisabledVisit
- ])
- describe('残疾人管理API集成测试', () => {
- let client: ReturnType<typeof testClient<typeof disabledPersonRoutes>>;
- let testToken: string;
- let testUser: UserEntity;
- let testFile: File;
- beforeEach(async () => {
- // 创建测试客户端
- client = testClient(disabledPersonRoutes);
- // 获取数据源
- const dataSource = await IntegrationTestDatabase.getDataSource();
- // 创建测试用户
- const userRepository = dataSource.getRepository(UserEntity);
- testUser = userRepository.create({
- username: `test_user_${Date.now()}`,
- password: 'test_password',
- nickname: '测试用户',
- registrationSource: 'web'
- });
- await userRepository.save(testUser);
- // 创建测试文件(用于照片集成测试)
- const fileRepository = dataSource.getRepository(File);
- testFile = fileRepository.create({
- name: 'test_photo.jpg',
- path: 'test_photo.jpg',
- type: 'image/jpeg',
- size: 1024,
- uploadUserId: testUser.id,
- uploadTime: new Date()
- });
- await fileRepository.save(testFile);
- // 生成测试用户的token
- testToken = JWTUtil.generateToken({
- id: testUser.id,
- username: testUser.username,
- roles: [{name:'user'}]
- });
- });
- describe('POST /createDisabledPerson', () => {
- it('应该成功创建残疾人基本信息', async () => {
- const createData = {
- name: '张三',
- gender: '男',
- idCard: '110101199001011234',
- disabilityId: 'D123456789',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市东城区',
- phone: '13800138000',
- province: '北京市',
- city: '北京市',
- // 新增字段
- canDirectContact: 1,
- isInBlackList: 0,
- jobStatus: 1,
- specificDisability: '左眼视力0.1,右眼视力0.2,需要助听器',
- // 日期字段
- idValidDate: new Date('2030-12-31'),
- disabilityValidDate: new Date('2030-12-31')
- };
- const response = await client.createDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.name).toBe(createData.name);
- expect(data.idCard).toBe(createData.idCard);
- expect(data.disabilityId).toBe(createData.disabilityId);
- // 验证新增字段
- expect(data.canDirectContact).toBe(createData.canDirectContact);
- expect(data.isInBlackList).toBe(createData.isInBlackList);
- expect(data.jobStatus).toBe(createData.jobStatus);
- expect(data.specificDisability).toBe(createData.specificDisability);
- // 验证日期字段
- expect(data.idValidDate).toBeDefined();
- expect(data.disabilityValidDate).toBeDefined();
- if (data.idValidDate) {
- expect(new Date(data.idValidDate).toISOString().split('T')[0]).toBe('2030-12-31');
- }
- if (data.disabilityValidDate) {
- expect(new Date(data.disabilityValidDate).toISOString().split('T')[0]).toBe('2030-12-31');
- }
- }
- });
- it('应该验证身份证号唯一性', async () => {
- // 先创建一个残疾人
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const existingPerson = disabledPersonRepository.create({
- name: '李四',
- gender: '女',
- idCard: '110101199001011235',
- disabilityId: 'D123456788',
- disabilityType: '视力残疾',
- disabilityLevel: '二级',
- idAddress: '北京市西城区',
- phone: '13900139000',
- province: '北京市',
- city: '北京市',
- // 新增字段
- canDirectContact: 0,
- isInBlackList: 0,
- jobStatus: 2,
- // 日期字段
- idValidDate: new Date('2035-05-15'),
- disabilityValidDate: new Date('2035-05-15')
- });
- await disabledPersonRepository.save(existingPerson);
- // 尝试创建相同身份证号的残疾人
- const createData = {
- name: '王五',
- gender: '男',
- idCard: '110101199001011235', // 重复的身份证号
- disabilityId: 'D123456777',
- disabilityType: '听力残疾',
- disabilityLevel: '三级',
- idAddress: '北京市朝阳区',
- phone: '13700137000',
- province: '北京市',
- city: '北京市',
- // 新增字段
- canDirectContact: 1,
- isInBlackList: 1,
- jobStatus: 3,
- // 日期字段
- idValidDate: new Date('2043-08-20'),
- disabilityValidDate: new Date('2043-08-20')
- };
- const response = await client.createDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(400);
- });
- it('应该验证必填字段', async () => {
- const createData = {
- name: '', // 空字符串,应该验证失败
- gender: '男',
- idCard: '110101199001011236',
- disabilityId: 'D123456776',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市海淀区',
- phone: '13600136000',
- province: '北京市',
- city: '北京市',
- // 新增字段(可选字段,不影响必填验证)
- canDirectContact: 1,
- isInBlackList: 0,
- jobStatus: 1,
- // 日期字段(可选字段,不影响必填验证)
- idValidDate: new Date('2028-03-10'),
- disabilityValidDate: new Date('2028-03-10')
- };
- const response = await client.createDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(400);
- });
- it('应该验证具体残疾部位和情况字段为空值', async () => {
- const createData = {
- name: '空值测试',
- gender: '男',
- idCard: '110101199001011236',
- disabilityId: 'D123456776',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市海淀区',
- phone: '13600136000',
- province: '北京市',
- city: '北京市',
- canDirectContact: 1,
- isInBlackList: 0,
- jobStatus: 1,
- // specificDisability 字段不提供,测试空值
- idValidDate: new Date('2028-03-10'),
- disabilityValidDate: new Date('2028-03-10')
- };
- const response = await client.createDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.name).toBe(createData.name);
- expect(data.specificDisability).toBeNull(); // 应该为null,因为数据库字段nullable: true
- }
- });
- it('应该验证具体残疾部位和情况字段为有效值', async () => {
- const createData = {
- name: '有效值测试',
- gender: '女',
- idCard: '110101199001011237',
- disabilityId: 'D123456775',
- disabilityType: '视力残疾',
- disabilityLevel: '二级',
- idAddress: '北京市朝阳区',
- phone: '13700137000',
- province: '北京市',
- city: '北京市',
- canDirectContact: 0,
- isInBlackList: 0,
- jobStatus: 0,
- specificDisability: '双眼视力均为0.05,需要导盲犬辅助',
- idValidDate: new Date('2030-06-15'),
- disabilityValidDate: new Date('2030-06-15')
- };
- const response = await client.createDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.name).toBe(createData.name);
- expect(data.specificDisability).toBe(createData.specificDisability);
- }
- });
- it('应该验证具体残疾部位和情况字段边界值(500字符)', async () => {
- // 生成500字符的字符串
- const maxLengthText = 'A'.repeat(500);
- const createData = {
- name: '边界值测试',
- gender: '男',
- idCard: '110101199001011238',
- disabilityId: 'D123456774',
- disabilityType: '听力残疾',
- disabilityLevel: '三级',
- idAddress: '北京市丰台区',
- phone: '13800138001',
- province: '北京市',
- city: '北京市',
- canDirectContact: 1,
- isInBlackList: 0,
- jobStatus: 1,
- specificDisability: maxLengthText,
- idValidDate: new Date('2032-08-20'),
- disabilityValidDate: new Date('2032-08-20')
- };
- const response = await client.createDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.name).toBe(createData.name);
- expect(data.specificDisability).toBe(createData.specificDisability);
- expect(data.specificDisability?.length).toBe(500);
- }
- });
- it('应该验证具体残疾部位和情况字段超过500字符限制', async () => {
- // 生成501字符的字符串
- const tooLongText = 'A'.repeat(501);
- const createData = {
- name: '超长测试',
- gender: '女',
- idCard: '110101199001011239',
- disabilityId: 'D123456773',
- disabilityType: '言语残疾',
- disabilityLevel: '四级',
- idAddress: '北京市石景山区',
- phone: '13900139001',
- province: '北京市',
- city: '北京市',
- canDirectContact: 0,
- isInBlackList: 0,
- jobStatus: 0,
- specificDisability: tooLongText,
- idValidDate: new Date('2034-12-31'),
- disabilityValidDate: new Date('2034-12-31')
- };
- const response = await client.createDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(400); // 应该返回400,因为超过长度限制
- });
- });
- describe('POST /deleteDisabledPerson', () => {
- it('应该成功删除残疾人', async () => {
- // 先创建一个残疾人
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const person = disabledPersonRepository.create({
- name: '测试删除人员',
- gender: '男',
- idCard: '110101199001011237',
- disabilityId: 'D123456775',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市石景山区',
- phone: '13500135000',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person);
- const deleteData = {
- id: person.id
- };
- const response = await client.deleteDisabledPerson.$post({
- json: deleteData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.success).toBe(true);
- // 验证残疾人已被删除
- const deletedPerson = await disabledPersonRepository.findOne({ where: { id: person.id } });
- expect(deletedPerson).toBeNull();
- }
- });
- it('应该处理不存在的残疾人ID', async () => {
- const deleteData = {
- id: 99999 // 不存在的ID
- };
- const response = await client.deleteDisabledPerson.$post({
- json: deleteData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(404);
- });
- });
- describe('POST /updateDisabledPerson', () => {
- it('应该成功更新残疾人信息', async () => {
- // 先创建一个残疾人
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const person = disabledPersonRepository.create({
- name: '原始姓名',
- gender: '男',
- idCard: '110101199001011238',
- disabilityId: 'D123456774',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市通州区',
- phone: '13400134000',
- province: '北京市',
- city: '北京市',
- // 新增字段初始值
- canDirectContact: 1,
- isInBlackList: 0,
- jobStatus: 1,
- // 日期字段初始值
- idValidDate: new Date('2023-01-01'),
- disabilityValidDate: new Date('2023-01-01')
- });
- await disabledPersonRepository.save(person);
- const updateData = {
- id: person.id,
- name: '更新后的姓名',
- gender: '女',
- phone: '13300133000',
- // 更新新增字段
- canDirectContact: 0,
- isInBlackList: 1,
- jobStatus: 1,
- // 更新日期字段
- idValidDate: new Date('2033-01-01'), // 更新有效期
- disabilityValidDate: new Date('2033-01-01') // 更新有效期
- };
- const response = await client.updateDisabledPerson.$post({
- json: updateData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.name).toBe(updateData.name);
- expect(data.gender).toBe(updateData.gender);
- expect(data.phone).toBe(updateData.phone);
- // 验证新增字段已更新
- expect(data.canDirectContact).toBe(updateData.canDirectContact);
- expect(data.isInBlackList).toBe(updateData.isInBlackList);
- expect(data.jobStatus).toBe(updateData.jobStatus);
- // 验证日期字段
- expect(data.idValidDate).toBeDefined();
- expect(data.disabilityValidDate).toBeDefined();
- if (data.idValidDate) {
- expect(new Date(data.idValidDate).toISOString().split('T')[0]).toBe('2033-01-01');
- }
- if (data.disabilityValidDate) {
- expect(new Date(data.disabilityValidDate).toISOString().split('T')[0]).toBe('2033-01-01');
- }
- }
- });
- it('应该验证身份证号唯一性(更新时)', async () => {
- // 创建两个残疾人
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const person1 = disabledPersonRepository.create({
- name: '人员A',
- gender: '男',
- idCard: '110101199001011239',
- disabilityId: 'D123456773',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市顺义区',
- phone: '13200132000',
- province: '北京市',
- city: '北京市',
- // 新增字段
- canDirectContact: 1,
- isInBlackList: 0,
- jobStatus: 1,
- // 日期字段
- idValidDate: new Date('2028-06-15'),
- disabilityValidDate: new Date('2028-06-15')
- });
- await disabledPersonRepository.save(person1);
- const person2 = disabledPersonRepository.create({
- name: '人员B',
- gender: '女',
- idCard: '110101199001011240',
- disabilityId: 'D123456772',
- disabilityType: '视力残疾',
- disabilityLevel: '二级',
- idAddress: '北京市大兴区',
- phone: '13100131000',
- province: '北京市',
- city: '北京市',
- // 新增字段
- canDirectContact: 0,
- isInBlackList: 1,
- jobStatus: 2,
- // 日期字段
- idValidDate: new Date('2034-09-20'),
- disabilityValidDate: new Date('2034-09-20')
- });
- await disabledPersonRepository.save(person2);
- // 尝试将人员2的身份证号改为人员1的身份证号
- const updateData = {
- id: person2.id,
- idCard: '110101199001011239' // 重复的身份证号
- };
- const response = await client.updateDisabledPerson.$post({
- json: updateData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(400);
- });
- it('应该处理不存在的残疾人', async () => {
- const updateData = {
- id: 99999, // 不存在的ID
- name: '新姓名'
- };
- const response = await client.updateDisabledPerson.$post({
- json: updateData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(404);
- });
- });
- describe('GET /getAllDisabledPersons', () => {
- it('应该成功获取残疾人列表(分页)', async () => {
- // 创建一些测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- for (let i = 1; i <= 5; i++) {
- const person = disabledPersonRepository.create({
- name: `残疾人${i}`,
- gender: i % 2 === 0 ? '女' : '男',
- idCard: `1101011990010112${40 + i}`,
- disabilityId: `D1234567${70 + i}`,
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: `北京市测试区${i}`,
- phone: `138001380${i}`,
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person);
- }
- const response = await client.getAllDisabledPersons.$get({
- query: {
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(5);
- expect(data.total).toBe(5);
- expect(data.data[0].name).toBe('残疾人5'); // 按ID降序排列
- }
- });
- it('应该处理分页参数', async () => {
- // 创建更多测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- for (let i = 1; i <= 15; i++) {
- const person = disabledPersonRepository.create({
- name: `分页人员${i}`,
- gender: i % 2 === 0 ? '女' : '男',
- idCard: `1101011990010113${i}`,
- disabilityId: `D1234568${i}`,
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: `北京市分页区${i}`,
- phone: `138001381${i}`,
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person);
- }
- const response = await client.getAllDisabledPersons.$get({
- query: {
- skip: 5,
- take: 5
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(5);
- expect(data.total).toBe(15);
- }
- });
- it('应该支持残疾类型筛选', async () => {
- // 创建测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- // 创建不同残疾类型的人员
- const person1 = disabledPersonRepository.create({
- name: '视力残疾人',
- gender: '男',
- idCard: '110101199001011351',
- disabilityId: 'D123456851',
- disabilityType: '视力残疾',
- disabilityLevel: '一级',
- idAddress: '北京市测试区',
- phone: '1380013851',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person1);
- const person2 = disabledPersonRepository.create({
- name: '肢体残疾人',
- gender: '女',
- idCard: '110101199001011352',
- disabilityId: 'D123456852',
- disabilityType: '肢体残疾',
- disabilityLevel: '二级',
- idAddress: '北京市测试区',
- phone: '1380013852',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person2);
- // 测试视力残疾筛选
- const response = await client.getAllDisabledPersons.$get({
- query: {
- disabilityType: '视力残疾',
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(1);
- expect(data.data[0].disabilityType).toBe('视力残疾');
- }
- });
- it('应该支持残疾级别筛选', async () => {
- // 创建测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- // 创建不同残疾级别的人员
- const person1 = disabledPersonRepository.create({
- name: '一级残疾人',
- gender: '男',
- idCard: '110101199001011361',
- disabilityId: 'D123456861',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市测试区',
- phone: '1380013861',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person1);
- const person2 = disabledPersonRepository.create({
- name: '二级残疾人',
- gender: '女',
- idCard: '110101199001011362',
- disabilityId: 'D123456862',
- disabilityType: '肢体残疾',
- disabilityLevel: '二级',
- idAddress: '北京市测试区',
- phone: '1380013862',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person2);
- // 测试一级残疾筛选
- const response = await client.getAllDisabledPersons.$get({
- query: {
- disabilityLevel: '一级',
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(1);
- expect(data.data[0].disabilityLevel).toBe('一级');
- }
- });
- it('应该支持省份筛选', async () => {
- // 创建测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- // 创建不同省份的人员
- const person1 = disabledPersonRepository.create({
- name: '北京人员',
- gender: '男',
- idCard: '110101199001011371',
- disabilityId: 'D123456871',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市测试区',
- phone: '1380013871',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person1);
- const person2 = disabledPersonRepository.create({
- name: '上海人员',
- gender: '女',
- idCard: '310101199001011372',
- disabilityId: 'D123456872',
- disabilityType: '肢体残疾',
- disabilityLevel: '二级',
- idAddress: '上海市测试区',
- phone: '1380013872',
- province: '上海市',
- city: '上海市'
- });
- await disabledPersonRepository.save(person2);
- // 测试北京筛选
- const response = await client.getAllDisabledPersons.$get({
- query: {
- province: '北京市',
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(1);
- expect(data.data[0].province).toBe('北京市');
- }
- });
- it('应该支持多条件组合筛选', async () => {
- // 创建测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- // 创建符合多个条件的人员
- const person1 = disabledPersonRepository.create({
- name: '北京一级视力残疾人',
- gender: '男',
- idCard: '110101199001011381',
- disabilityId: 'D123456881',
- disabilityType: '视力残疾',
- disabilityLevel: '一级',
- idAddress: '北京市测试区',
- phone: '1380013881',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person1);
- // 创建不符合全部条件的人员
- const person2 = disabledPersonRepository.create({
- name: '北京二级肢体残疾人',
- gender: '女',
- idCard: '110101199001011382',
- disabilityId: 'D123456882',
- disabilityType: '肢体残疾',
- disabilityLevel: '二级',
- idAddress: '北京市测试区',
- phone: '1380013882',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person2);
- // 测试多条件组合筛选:北京 + 一级 + 视力残疾
- const response = await client.getAllDisabledPersons.$get({
- query: {
- province: '北京市',
- disabilityType: '视力残疾',
- disabilityLevel: '一级',
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(1);
- expect(data.data[0].name).toBe('北京一级视力残疾人');
- }
- });
- it('应该支持银行卡类别筛选', async () => {
- // 创建测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const bankNameRepository = dataSource.getRepository(BankName);
- const bankCardRepository = dataSource.getRepository(DisabledBankCard);
- // 创建银行名称
- const bankName1 = bankNameRepository.create({
- name: '中国工商银行',
- code: 'ICBC',
- status: 1
- });
- await bankNameRepository.save(bankName1);
- const bankName2 = bankNameRepository.create({
- name: '中国建设银行',
- code: 'CCB',
- status: 1
- });
- await bankNameRepository.save(bankName2);
- // 创建人员1 - 有工商银行卡
- const person1 = disabledPersonRepository.create({
- name: '工商银行用户',
- gender: '男',
- idCard: '110101199001011391',
- disabilityId: 'D123456891',
- disabilityType: '视力残疾',
- disabilityLevel: '一级',
- idAddress: '北京市测试区',
- phone: '1380013891',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person1);
- // 为人员1创建工商银行卡
- const bankCard1 = bankCardRepository.create({
- personId: person1.id,
- subBankName: '北京分行',
- bankNameId: bankName1.id,
- cardNumber: '6222001234567890123',
- cardholderName: '工商银行用户',
- cardType: '储蓄卡',
- fileId: testFile.id,
- isDefault: 1
- });
- await bankCardRepository.save(bankCard1);
- // 创建人员2 - 有建设银行卡
- const person2 = disabledPersonRepository.create({
- name: '建设银行用户',
- gender: '女',
- idCard: '110101199001011392',
- disabilityId: 'D123456892',
- disabilityType: '肢体残疾',
- disabilityLevel: '二级',
- idAddress: '北京市测试区',
- phone: '1380013892',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person2);
- // 为人员2创建建设银行卡
- const bankCard2 = bankCardRepository.create({
- personId: person2.id,
- subBankName: '北京分行',
- bankNameId: bankName2.id,
- cardNumber: '6227001234567890123',
- cardholderName: '建设银行用户',
- cardType: '信用卡',
- fileId: testFile.id,
- isDefault: 1
- });
- await bankCardRepository.save(bankCard2);
- // 测试工商银行筛选
- const response = await client.getAllDisabledPersons.$get({
- query: {
- bankNameId: bankName1.id,
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(1);
- expect(data.data[0].name).toBe('工商银行用户');
- }
- });
- it('应该支持银行卡类型筛选', async () => {
- // 创建测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const bankNameRepository = dataSource.getRepository(BankName);
- const bankCardRepository = dataSource.getRepository(DisabledBankCard);
- // 创建银行名称
- const bankName1 = bankNameRepository.create({
- name: '中国工商银行',
- code: 'ICBC',
- status: 1
- });
- await bankNameRepository.save(bankName1);
- const bankName2 = bankNameRepository.create({
- name: '中国建设银行',
- code: 'CCB',
- status: 1
- });
- await bankNameRepository.save(bankName2);
- // 创建人员1 - 有储蓄卡
- const person1 = disabledPersonRepository.create({
- name: '储蓄卡用户',
- gender: '男',
- idCard: '110101199001011393',
- disabilityId: 'D123456893',
- disabilityType: '视力残疾',
- disabilityLevel: '一级',
- idAddress: '北京市测试区',
- phone: '1380013893',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person1);
- // 为人员1创建储蓄卡
- const bankCard1 = bankCardRepository.create({
- personId: person1.id,
- subBankName: '北京分行',
- bankNameId: bankName1.id,
- cardNumber: '6222001234567890124',
- cardholderName: '储蓄卡用户',
- cardType: '储蓄卡',
- fileId: testFile.id,
- isDefault: 1
- });
- await bankCardRepository.save(bankCard1);
- // 创建人员2 - 有信用卡
- const person2 = disabledPersonRepository.create({
- name: '信用卡用户',
- gender: '女',
- idCard: '110101199001011394',
- disabilityId: 'D123456894',
- disabilityType: '肢体残疾',
- disabilityLevel: '二级',
- idAddress: '北京市测试区',
- phone: '1380013894',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person2);
- // 为人员2创建信用卡
- const bankCard2 = bankCardRepository.create({
- personId: person2.id,
- subBankName: '北京分行',
- bankNameId: bankName2.id,
- cardNumber: '6227001234567890124',
- cardholderName: '信用卡用户',
- cardType: '信用卡',
- fileId: testFile.id,
- isDefault: 1
- });
- await bankCardRepository.save(bankCard2);
- // 测试储蓄卡筛选
- const response = await client.getAllDisabledPersons.$get({
- query: {
- cardType: '储蓄卡',
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(1);
- expect(data.data[0].name).toBe('储蓄卡用户');
- }
- });
- });
- describe('GET /searchDisabledPersons', () => {
- it('应该成功按姓名搜索残疾人', async () => {
- // 创建测试数据
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const person1 = disabledPersonRepository.create({
- name: '张三',
- gender: '男',
- idCard: '110101199001011241',
- disabilityId: 'D123456771',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市昌平区',
- phone: '13000130001',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person1);
- const person2 = disabledPersonRepository.create({
- name: '李四',
- gender: '女',
- idCard: '110101199001011242',
- disabilityId: 'D123456770',
- disabilityType: '视力残疾',
- disabilityLevel: '二级',
- idAddress: '北京市平谷区',
- phone: '13000130002',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person2);
- const response = await client.searchDisabledPersons.$get({
- query: {
- keyword: '张三',
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.data).toHaveLength(1);
- expect(data.data[0].name).toBe('张三');
- }
- });
- it('应该验证搜索关键词不能为空', async () => {
- const response = await client.searchDisabledPersons.$get({
- query: {
- keyword: '', // 空关键词
- skip: 0,
- take: 10
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(400);
- });
- });
- describe('GET /getDisabledPerson/{id}', () => {
- it('应该成功获取单个残疾人详情', async () => {
- // 先创建一个残疾人
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const person = disabledPersonRepository.create({
- name: '测试人员详情',
- gender: '男',
- idCard: '110101199001011243',
- disabilityId: 'D123456769',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市怀柔区',
- phone: '13000130003',
- province: '北京市',
- city: '北京市',
- canDirectContact: 1,
- isMarried: 1
- });
- await disabledPersonRepository.save(person);
- const response = await client.getDisabledPerson[':id'].$get({
- param: {
- id: person.id
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data?.name).toBe('测试人员详情');
- expect(data?.canDirectContact).toBe(1);
- }
- });
- it('应该处理不存在的残疾人ID', async () => {
- const response = await client.getDisabledPerson[':id'].$get({
- param: {
- id: 99999 // 不存在的ID
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200); // 返回200,但数据为null
- if (response.status === 200) {
- const data = await response.json();
- expect(data).toBeNull();
- }
- });
- });
- describe('GET /getDisabledPersonByIdCard', () => {
- it('应该成功根据身份证号查询残疾人', async () => {
- // 先创建一个残疾人
- const dataSource = await IntegrationTestDatabase.getDataSource();
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const person = disabledPersonRepository.create({
- name: '身份证查询测试',
- gender: '女',
- idCard: '110101199001011244',
- disabilityId: 'D123456768',
- disabilityType: '听力残疾',
- disabilityLevel: '三级',
- idAddress: '北京市密云区',
- phone: '13000130004',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person);
- const response = await client.findByIdCard[':idCard'].$get({
- param: {
- idCard: '110101199001011244'
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data?.name).toBe('身份证查询测试');
- expect(data?.idCard).toBe('110101199001011244');
- }
- });
- it('应该处理不存在的身份证号', async () => {
- const response = await client.findByIdCard[':idCard'].$get({
- param: {
- idCard: '999999999999999999' // 不存在的身份证号
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200); // 返回200,但数据为null
- if (response.status === 200) {
- const data = await response.json();
- expect(data).toBeNull();
- }
- });
- });
- describe('POST /createAggregatedDisabledPerson', () => {
- it('应该成功创建聚合残疾人信息(包含所有关联数据)', async () => {
- const createData = {
- personInfo: {
- name: '聚合创建测试',
- gender: '男',
- idCard: '110101199001011245',
- disabilityId: 'D123456767',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市延庆区',
- phone: '13000130005',
- province: '北京市',
- city: '北京市',
- // 新增字段
- canDirectContact: 1,
- isInBlackList: 0,
- jobStatus: 1,
- specificDisability: '左腿截肢,右腿行动不便,需要轮椅',
- // 日期字段
- idValidDate: new Date('2045-11-30'),
- disabilityValidDate: new Date('2045-11-30')
- },
- bankCards: [
- {
- subBankName: '北京分行',
- bankNameId: 1, // 假设银行名称ID为1
- cardNumber: '6222021234567890123',
- cardholderName: '聚合创建测试',
- cardType: '储蓄卡',
- fileId: testFile.id,
- isDefault: 0
- }
- ],
- photos: [
- {
- photoType: '身份证照片',
- fileId: testFile.id // 使用测试文件ID
- }
- ],
- remarks: [
- {
- remarkContent: '家庭经济困难,需要帮助',
- operatorId: 1
- }
- ],
- visits: [
- {
- visitDate: '2025-12-02T10:00:00Z',
- visitType: '电话回访',
- visitContent: '初次回访,了解基本情况',
- visitorId: 1
- }
- ]
- };
- const response = await client.createAggregatedDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data.personInfo.name).toBe('聚合创建测试');
- // 验证新增字段
- expect(data.personInfo.canDirectContact).toBe(1);
- expect(data.personInfo.isInBlackList).toBe(0);
- expect(data.personInfo.jobStatus).toBe(1);
- expect(data.personInfo.specificDisability).toBe('左腿截肢,右腿行动不便,需要轮椅');
- // 验证日期字段
- expect(data.personInfo.idValidDate).toBeDefined();
- expect(data.personInfo.disabilityValidDate).toBeDefined();
- if (data.personInfo.idValidDate) {
- expect(new Date(data.personInfo.idValidDate).toISOString().split('T')[0]).toBe('2045-11-30');
- }
- if (data.personInfo.disabilityValidDate) {
- expect(new Date(data.personInfo.disabilityValidDate).toISOString().split('T')[0]).toBe('2045-11-30');
- }
- expect(data.bankCards).toHaveLength(1);
- expect(data.photos).toHaveLength(1);
- expect(data.remarks).toHaveLength(1);
- expect(data.visits).toHaveLength(1);
- // 验证文件集成
- expect(data.photos[0].fileId).toBe(testFile.id);
- }
- });
- it('应该验证文件ID的有效性', async () => {
- const createData = {
- personInfo: {
- name: '文件验证测试',
- gender: '女',
- idCard: '110101199001011246',
- disabilityId: 'D123456766',
- disabilityType: '视力残疾',
- disabilityLevel: '二级',
- idAddress: '北京市房山区',
- phone: '13000130006',
- province: '北京市',
- city: '北京市',
- // 新增字段
- canDirectContact: 0,
- isInBlackList: 1,
- jobStatus: 2,
- // 日期字段
- idValidDate: new Date('2036-07-25'),
- disabilityValidDate: new Date('2036-07-25')
- },
- photos: [
- {
- photoType: '身份证照片',
- fileId: 99999 // 不存在的文件ID
- }
- ]
- };
- const response = await client.createAggregatedDisabledPerson.$post({
- json: createData
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(400); // 应该返回400,因为文件ID无效
- });
- });
- describe('GET /getAggregatedDisabledPerson/{personId}', () => {
- it('应该成功获取聚合残疾人信息', async () => {
- // 先创建一个完整的残疾人数据(包含所有关联数据)
- const dataSource = await IntegrationTestDatabase.getDataSource();
- // 创建残疾人
- const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
- const person = disabledPersonRepository.create({
- name: '聚合查询测试',
- gender: '男',
- idCard: '110101199001011247',
- disabilityId: 'D123456765',
- disabilityType: '肢体残疾',
- disabilityLevel: '一级',
- idAddress: '北京市门头沟区',
- phone: '13000130007',
- province: '北京市',
- city: '北京市'
- });
- await disabledPersonRepository.save(person);
- // 创建银行卡
- const bankCardRepository = dataSource.getRepository(DisabledBankCard);
- const bankCard = bankCardRepository.create({
- personId: person.id,
- subBankName: '北京分行',
- bankNameId: 1, // 假设银行名称ID为1
- cardNumber: '6227001234567890123',
- cardholderName: '聚合查询测试',
- cardType: '储蓄卡',
- fileId: testFile.id,
- isDefault: 0
- });
- await bankCardRepository.save(bankCard);
- // 创建照片(使用测试文件)
- const photoRepository = dataSource.getRepository(DisabledPhoto);
- const photo = photoRepository.create({
- personId: person.id,
- photoType: '身份证照片',
- fileId: testFile.id
- });
- await photoRepository.save(photo);
- // 创建备注
- const remarkRepository = dataSource.getRepository(DisabledRemark);
- const remark = remarkRepository.create({
- personId: person.id,
- remarkContent: '目前无工作,需要就业帮助',
- operatorId: 1
- });
- await remarkRepository.save(remark);
- // 创建回访记录
- const visitRepository = dataSource.getRepository(DisabledVisit);
- const visit = visitRepository.create({
- personId: person.id,
- visitDate: new Date('2025-12-01T14:30:00Z'),
- visitType: '上门回访',
- visitContent: '了解就业需求',
- visitorId: 2
- });
- await visitRepository.save(visit);
- const response = await client.getAggregatedDisabledPerson[':id'].$get({
- param: {
- id: person.id
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- // 调试:打印响应状态和错误信息
- console.debug('响应状态:', response.status);
- if (response.status !== 200) {
- const errorText = await response.text();
- console.debug('错误响应:', errorText);
- }
- expect(response.status).toBe(200);
- if (response.status === 200) {
- const data = await response.json();
- expect(data).not.toBeNull();
- expect(data!.personInfo.name).toBe('聚合查询测试');
- expect(data!.bankCards).toHaveLength(1);
- expect(data!.photos).toHaveLength(1);
- expect(data!.remarks).toHaveLength(1);
- expect(data!.visits).toHaveLength(1);
- // 验证文件数据完整性
- expect(data!.photos[0].fileId).toBe(testFile.id);
- }
- });
- it('应该处理不存在的残疾人ID', async () => {
- const response = await client.getAggregatedDisabledPerson[':id'].$get({
- param: {
- id: 99999 // 不存在的ID
- }
- }, {
- headers: {
- 'Authorization': `Bearer ${testToken}`
- }
- });
- expect(response.status).toBe(404);
- });
- });
- describe('认证测试', () => {
- it('应该验证所有端点需要认证', async () => {
- // 测试没有token的情况
- const response = await client.createDisabledPerson.$post({
- json: {
- name: '测试人员',
- gender: '男',
- idCard: '110101199001011235',
- disabilityId: 'D123456789',
- disabilityType: '视力残疾',
- disabilityLevel: '一级',
- idAddress: '北京市东城区',
- phone: '13800138000',
- province: '北京市',
- city: '北京市'
- }
- });
- expect(response.status).toBe(401);
- });
- it('应该验证无效token', async () => {
- const response = await client.createDisabledPerson.$post({
- json: {
- name: '测试人员',
- gender: '男',
- idCard: '110101199001011236',
- disabilityId: 'D123456790',
- disabilityType: '视力残疾',
- disabilityLevel: '一级',
- idAddress: '北京市东城区',
- phone: '13800138001',
- province: '北京市',
- city: '北京市'
- }
- }, {
- headers: {
- 'Authorization': 'Bearer invalid_token'
- }
- });
- expect(response.status).toBe(401);
- });
- });
- });
|