Quellcode durchsuchen

✅ test(integration): 完善支付相关集成测试数据准备

- 为支付回调测试添加商户、供货商和配送地址记录创建逻辑
- 将订单创建时的addressId、merchantId和supplierId从0更新为实际关联记录ID
- 修复支付测试中导入的实体类名,从UserEntity改为UserEntityMt,Role改为RoleMt,File改为FileMt
- 调整setupIntegrationDatabaseHooksWithEntities中注册的实体类型以匹配多租户版本
yourname vor 1 Monat
Ursprung
Commit
3c1a30b021

+ 94 - 6
packages/mini-payment-mt/tests/integration/payment-callback.integration.test.ts

@@ -60,6 +60,50 @@ describe('支付回调API集成测试 - 多租户版本', () => {
     });
     await userRepository.save(testUser);
 
+    // 创建商户记录
+    const merchantRepository = dataSource.getRepository(MerchantMt);
+    const testMerchant = merchantRepository.create({
+      tenantId: 1,
+      name: '测试商户',
+      username: `m${Date.now()}`.slice(-19), // 确保不超过20字符
+      password: 'test_password',
+      state: 1,
+      createdBy: testUser.id,
+      updatedBy: testUser.id
+    });
+    await merchantRepository.save(testMerchant);
+
+    // 创建供货商记录
+    const supplierRepository = dataSource.getRepository(SupplierMt);
+    const testSupplier = supplierRepository.create({
+      tenantId: 1,
+      name: '测试供货商',
+      username: `s${Date.now()}`.slice(-49), // 确保不超过50字符
+      password: 'test_password',
+      state: 1,
+      createdBy: testUser.id,
+      updatedBy: testUser.id
+    });
+    await supplierRepository.save(testSupplier);
+
+    // 创建配送地址记录
+    const addressRepository = dataSource.getRepository(DeliveryAddressMt);
+    const testAddress = addressRepository.create({
+      tenantId: 1,
+      userId: testUser.id,
+      name: '测试收货人',
+      mobile: '13800138000',
+      province: 110000,
+      city: 110100,
+      district: 110101,
+      town: 110101001,
+      address: '测试地址',
+      isDefault: 1,
+      createdBy: testUser.id,
+      updatedBy: testUser.id
+    });
+    await addressRepository.save(testAddress);
+
     // 创建测试订单
     const orderRepository = dataSource.getRepository(OrderMt);
     testOrder = orderRepository.create({
@@ -73,9 +117,9 @@ describe('支付回调API集成测试 - 多租户版本', () => {
       payType: 2,
       payState: 0, // 未支付
       state: 0,
-      addressId: 0,
-      merchantId: 0,
-      supplierId: 0,
+      addressId: testAddress.id,
+      merchantId: testMerchant.id,
+      supplierId: testSupplier.id,
       createdBy: testUser.id,
       updatedBy: testUser.id
     });
@@ -254,6 +298,50 @@ describe('支付回调API集成测试 - 多租户版本', () => {
       });
       await userRepository.save(testUser2);
 
+      // 创建第二个租户的商户记录
+      const merchantRepository = dataSource.getRepository(MerchantMt);
+      const testMerchant2 = merchantRepository.create({
+        tenantId: 2,
+        name: '测试商户2',
+        username: `test_merchant2_${Date.now()}`,
+        password: 'test_password',
+        state: 1,
+        createdBy: testUser2.id,
+        updatedBy: testUser2.id
+      });
+      await merchantRepository.save(testMerchant2);
+
+      // 创建第二个租户的供货商记录
+      const supplierRepository = dataSource.getRepository(SupplierMt);
+      const testSupplier2 = supplierRepository.create({
+        tenantId: 2,
+        name: '测试供货商2',
+        username: `test_supplier2_${Date.now()}`,
+        password: 'test_password',
+        state: 1,
+        createdBy: testUser2.id,
+        updatedBy: testUser2.id
+      });
+      await supplierRepository.save(testSupplier2);
+
+      // 创建第二个租户的配送地址记录
+      const addressRepository = dataSource.getRepository(DeliveryAddressMt);
+      const testAddress2 = addressRepository.create({
+        tenantId: 2,
+        userId: testUser2.id,
+        name: '测试收货人2',
+        mobile: '13800138001',
+        province: 110000,
+        city: 110100,
+        district: 110101,
+        town: 110101001,
+        address: '测试地址2',
+        isDefault: 1,
+        createdBy: testUser2.id,
+        updatedBy: testUser2.id
+      });
+      await addressRepository.save(testAddress2);
+
       const orderRepository = dataSource.getRepository(OrderMt);
       const testOrder2 = orderRepository.create({
         tenantId: 2,
@@ -266,9 +354,9 @@ describe('支付回调API集成测试 - 多租户版本', () => {
         payType: 2,
         payState: 0,
         state: 0,
-        addressId: 0,
-        merchantId: 0,
-        supplierId: 0,
+        addressId: testAddress2.id,
+        merchantId: testMerchant2.id,
+        supplierId: testSupplier2.id,
         createdBy: testUser2.id,
         updatedBy: testUser2.id
       });

+ 5 - 5
packages/mini-payment-mt/tests/integration/payment.integration.test.ts

@@ -7,9 +7,9 @@ import {
 import { PaymentMtRoutes } from '../../src/routes/payment.mt.routes.js';
 import { PaymentMtEntity } from '../../src/entities/payment.mt.entity.js';
 import { PaymentStatus } from '../../src/entities/payment.types.js';
-import { UserEntity } from '@d8d/user-module';
-import { Role } from '@d8d/user-module';
-import { File } from '@d8d/file-module';
+import { UserEntityMt } from '@d8d/user-module-mt';
+import { RoleMt } from '@d8d/user-module-mt';
+import { FileMt } from '@d8d/file-module-mt';
 import { JWTUtil } from '@d8d/shared-utils';
 import { config } from 'dotenv';
 import { resolve } from 'path';
@@ -22,12 +22,12 @@ config({ path: resolve(process.cwd(), '.env.test') });
 vi.mock('wechatpay-node-v3')
 
 // 设置集成测试钩子
-setupIntegrationDatabaseHooksWithEntities([PaymentMtEntity, UserEntity, File, Role])
+setupIntegrationDatabaseHooksWithEntities([PaymentMtEntity, UserEntityMt, FileMt, RoleMt])
 
 describe('支付API集成测试', () => {
   let client: ReturnType<typeof testClient<typeof PaymentMtRoutes>>;
   let testToken: string;
-  let testUser: UserEntity;
+  let testUser: UserEntityMt;
   let testPayment: PaymentMtEntity;
 
   beforeEach(async () => {