|
|
@@ -4,6 +4,9 @@ import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } fr
|
|
|
import { JWTUtil } from '@d8d/shared-utils';
|
|
|
import { UserEntity, Role } from '@d8d/user-module';
|
|
|
import { File } from '@d8d/file-module';
|
|
|
+import { DisabledPerson, DisabledBankCard, DisabledPhoto, DisabledRemark, DisabledVisit } from '@d8d/allin-disability-module';
|
|
|
+import { BankName } from '@d8d/bank-names-module';
|
|
|
+import { DataSource } from 'typeorm';
|
|
|
import orderRoutes from '../../src/routes/order.routes';
|
|
|
import { EmploymentOrder } from '../../src/entities/employment-order.entity';
|
|
|
import { OrderPerson } from '../../src/entities/order-person.entity';
|
|
|
@@ -13,13 +16,14 @@ import { OrderStatus, WorkStatus } from '@d8d/allin-enums';
|
|
|
import { OrderTestDataFactory } from '../utils/test-data-factory';
|
|
|
|
|
|
// 设置集成测试钩子
|
|
|
-setupIntegrationDatabaseHooksWithEntities([UserEntity, File, Role, EmploymentOrder, OrderPerson, OrderPersonAsset])
|
|
|
+setupIntegrationDatabaseHooksWithEntities([UserEntity, File, Role, DisabledPerson, DisabledBankCard, DisabledPhoto, DisabledRemark, DisabledVisit, BankName, EmploymentOrder, OrderPerson, OrderPersonAsset])
|
|
|
|
|
|
describe('订单管理API集成测试', () => {
|
|
|
let client: ReturnType<typeof testClient<typeof orderRoutes>>;
|
|
|
let testToken: string;
|
|
|
let testUser: UserEntity;
|
|
|
let testFile: File;
|
|
|
+ let testDisabledPerson: DisabledPerson;
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
// 创建测试客户端
|
|
|
@@ -58,6 +62,21 @@ describe('订单管理API集成测试', () => {
|
|
|
updatedAt: new Date()
|
|
|
});
|
|
|
await fileRepository.save(testFile);
|
|
|
+
|
|
|
+ // 创建测试银行名称记录(用于DisabledBankCard外键约束)
|
|
|
+ const bankNameRepository = dataSource.getRepository(BankName);
|
|
|
+ const testBankName = bankNameRepository.create({
|
|
|
+ name: '测试银行',
|
|
|
+ code: 'TEST001',
|
|
|
+ remark: '测试银行',
|
|
|
+ createdBy: testUser.id,
|
|
|
+ updatedBy: testUser.id,
|
|
|
+ status: 1
|
|
|
+ });
|
|
|
+ await bankNameRepository.save(testBankName);
|
|
|
+
|
|
|
+ // 创建测试残疾人记录(用于外键约束)
|
|
|
+ testDisabledPerson = await OrderTestDataFactory.createTestDisabledPerson(dataSource);
|
|
|
});
|
|
|
|
|
|
describe('POST /order/create', () => {
|
|
|
@@ -483,15 +502,62 @@ describe('订单管理API集成测试', () => {
|
|
|
});
|
|
|
|
|
|
it('应该成功批量添加人员到订单', async () => {
|
|
|
+ // 创建两个测试残疾人记录
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
|
|
|
+
|
|
|
+ // 直接创建最简单的DisabledPerson记录
|
|
|
+ const disabledPerson1 = disabledPersonRepository.create({
|
|
|
+ name: '测试1',
|
|
|
+ gender: '男',
|
|
|
+ idCard: '1',
|
|
|
+ disabilityId: '1',
|
|
|
+ disabilityType: '肢体',
|
|
|
+ disabilityLevel: '三级',
|
|
|
+ idAddress: '地址',
|
|
|
+ phone: '13800138000',
|
|
|
+ canDirectContact: 1,
|
|
|
+ province: '省',
|
|
|
+ city: '市',
|
|
|
+ district: '区',
|
|
|
+ detailedAddress: '地址',
|
|
|
+ isInBlackList: 0,
|
|
|
+ jobStatus: 0,
|
|
|
+ createTime: new Date(),
|
|
|
+ updateTime: new Date()
|
|
|
+ });
|
|
|
+ await disabledPersonRepository.save(disabledPerson1);
|
|
|
+
|
|
|
+ const disabledPerson2 = disabledPersonRepository.create({
|
|
|
+ name: '测试2',
|
|
|
+ gender: '女',
|
|
|
+ idCard: '2',
|
|
|
+ disabilityId: '2',
|
|
|
+ disabilityType: '视力',
|
|
|
+ disabilityLevel: '二级',
|
|
|
+ idAddress: '地址',
|
|
|
+ phone: '13800138001',
|
|
|
+ canDirectContact: 1,
|
|
|
+ province: '省',
|
|
|
+ city: '市',
|
|
|
+ district: '区',
|
|
|
+ detailedAddress: '地址',
|
|
|
+ isInBlackList: 0,
|
|
|
+ jobStatus: 0,
|
|
|
+ createTime: new Date(),
|
|
|
+ updateTime: new Date()
|
|
|
+ });
|
|
|
+ await disabledPersonRepository.save(disabledPerson2);
|
|
|
+
|
|
|
const batchData = {
|
|
|
persons: [
|
|
|
{
|
|
|
- personId: 1001,
|
|
|
+ personId: disabledPerson1.id,
|
|
|
joinDate: new Date().toISOString(),
|
|
|
salaryDetail: 5000.00
|
|
|
},
|
|
|
{
|
|
|
- personId: 1002,
|
|
|
+ personId: disabledPerson2.id,
|
|
|
joinDate: new Date().toISOString(),
|
|
|
salaryDetail: 6000.00
|
|
|
}
|
|
|
@@ -525,12 +591,15 @@ describe('订单管理API集成测试', () => {
|
|
|
});
|
|
|
|
|
|
it('应该处理重复的人员添加', async () => {
|
|
|
- // 先添加一个人员
|
|
|
+ // 创建两个测试残疾人记录
|
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const [disabledPerson1, disabledPerson2] = await OrderTestDataFactory.createTestDisabledPersons(dataSource, 2);
|
|
|
const orderPersonRepository = dataSource.getRepository(OrderPerson);
|
|
|
+
|
|
|
+ // 先添加一个人员
|
|
|
const existingPerson = orderPersonRepository.create({
|
|
|
orderId: testOrder.id,
|
|
|
- personId: 1001,
|
|
|
+ personId: disabledPerson1.id,
|
|
|
joinDate: new Date(),
|
|
|
workStatus: WorkStatus.NOT_WORKING,
|
|
|
salaryDetail: 5000.00
|
|
|
@@ -540,12 +609,12 @@ describe('订单管理API集成测试', () => {
|
|
|
const batchData = {
|
|
|
persons: [
|
|
|
{
|
|
|
- personId: 1001, // 已存在的人员
|
|
|
+ personId: disabledPerson1.id, // 已存在的人员
|
|
|
joinDate: new Date().toISOString(),
|
|
|
salaryDetail: 5000.00
|
|
|
},
|
|
|
{
|
|
|
- personId: 1002, // 新人员
|
|
|
+ personId: disabledPerson2.id, // 新人员
|
|
|
joinDate: new Date().toISOString(),
|
|
|
salaryDetail: 6000.00
|
|
|
}
|
|
|
@@ -631,6 +700,7 @@ describe('订单管理API集成测试', () => {
|
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
const orderRepository = dataSource.getRepository(EmploymentOrder);
|
|
|
const orderPersonRepository = dataSource.getRepository(OrderPerson);
|
|
|
+ const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
|
|
|
|
|
|
testOrder = new EmploymentOrder({
|
|
|
orderName: '资产测试订单',
|
|
|
@@ -643,9 +713,12 @@ describe('订单管理API集成测试', () => {
|
|
|
});
|
|
|
await orderRepository.save(testOrder);
|
|
|
|
|
|
+ // 先创建残疾人记录
|
|
|
+ const testDisabledPerson = await OrderTestDataFactory.createTestDisabledPerson(dataSource);
|
|
|
+
|
|
|
testOrderPerson = orderPersonRepository.create({
|
|
|
orderId: testOrder.id,
|
|
|
- personId: 1001,
|
|
|
+ personId: testDisabledPerson.id,
|
|
|
joinDate: new Date(),
|
|
|
workStatus: WorkStatus.NOT_WORKING,
|
|
|
salaryDetail: 5000.00
|
|
|
@@ -742,6 +815,7 @@ describe('订单管理API集成测试', () => {
|
|
|
const orderRepository = dataSource.getRepository(EmploymentOrder);
|
|
|
const orderPersonRepository = dataSource.getRepository(OrderPerson);
|
|
|
const assetRepository = dataSource.getRepository(OrderPersonAsset);
|
|
|
+ const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
|
|
|
|
|
|
testOrder = new EmploymentOrder({
|
|
|
orderName: '资产查询测试订单',
|
|
|
@@ -754,9 +828,12 @@ describe('订单管理API集成测试', () => {
|
|
|
});
|
|
|
await orderRepository.save(testOrder);
|
|
|
|
|
|
+ // 先创建残疾人记录
|
|
|
+ const testDisabledPerson = await OrderTestDataFactory.createTestDisabledPerson(dataSource);
|
|
|
+
|
|
|
testOrderPerson = orderPersonRepository.create({
|
|
|
orderId: testOrder.id,
|
|
|
- personId: 1001,
|
|
|
+ personId: testDisabledPerson.id,
|
|
|
joinDate: new Date(),
|
|
|
workStatus: WorkStatus.NOT_WORKING,
|
|
|
salaryDetail: 5000.00
|
|
|
@@ -896,6 +973,7 @@ describe('订单管理API集成测试', () => {
|
|
|
const orderRepository = dataSource.getRepository(EmploymentOrder);
|
|
|
const orderPersonRepository = dataSource.getRepository(OrderPerson);
|
|
|
const assetRepository = dataSource.getRepository(OrderPersonAsset);
|
|
|
+ const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
|
|
|
|
|
|
const testOrder = new EmploymentOrder({
|
|
|
orderName: '资产删除测试订单',
|
|
|
@@ -908,9 +986,12 @@ describe('订单管理API集成测试', () => {
|
|
|
});
|
|
|
await orderRepository.save(testOrder);
|
|
|
|
|
|
+ // 先创建残疾人记录
|
|
|
+ const testDisabledPerson = await OrderTestDataFactory.createTestDisabledPerson(dataSource);
|
|
|
+
|
|
|
const testOrderPerson = orderPersonRepository.create({
|
|
|
orderId: testOrder.id,
|
|
|
- personId: 1001,
|
|
|
+ personId: testDisabledPerson.id,
|
|
|
joinDate: new Date(),
|
|
|
workStatus: WorkStatus.NOT_WORKING,
|
|
|
salaryDetail: 5000.00
|