|
|
@@ -4,7 +4,7 @@ import { SupplierMt } from '@d8d/supplier-module-mt';
|
|
|
import { MerchantMt } from '@d8d/merchant-module-mt';
|
|
|
import { DeliveryAddressMt } from '@d8d/delivery-address-module-mt';
|
|
|
import { FileMt } from '@d8d/file-module-mt';
|
|
|
-import { GoodsMt } from '@d8d/goods-module-mt';
|
|
|
+import { GoodsMt, GoodsCategoryMt } from '@d8d/goods-module-mt';
|
|
|
import { AreaEntityMt } from '@d8d/geo-areas-mt';
|
|
|
import { OrderMt, OrderGoodsMt, OrderRefundMt } from '../../src/entities/index';
|
|
|
|
|
|
@@ -127,6 +127,22 @@ export class OrdersTestFactory {
|
|
|
return await addressRepository.save(address);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建测试商品分类
|
|
|
+ */
|
|
|
+ async createTestGoodsCategory(overrides: Partial<GoodsCategoryMt> = {}): Promise<GoodsCategoryMt> {
|
|
|
+ const categoryRepository = this.dataSource.getRepository(GoodsCategoryMt);
|
|
|
+ const tenantId = overrides.tenantId || 1;
|
|
|
+
|
|
|
+ const category = categoryRepository.create({
|
|
|
+ tenantId,
|
|
|
+ name: `测试分类_${Math.floor(Math.random() * 100000)}`,
|
|
|
+ sort: 1,
|
|
|
+ ...overrides
|
|
|
+ });
|
|
|
+ return await categoryRepository.save(category);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建测试商品
|
|
|
*/
|
|
|
@@ -134,6 +150,9 @@ export class OrdersTestFactory {
|
|
|
const goodsRepository = this.dataSource.getRepository(GoodsMt);
|
|
|
const tenantId = overrides.tenantId || 1;
|
|
|
|
|
|
+ // 创建测试商品分类
|
|
|
+ const testCategory = await this.createTestGoodsCategory({ tenantId });
|
|
|
+
|
|
|
const goods = goodsRepository.create({
|
|
|
tenantId,
|
|
|
name: `测试商品_${Math.floor(Math.random() * 100000)}`,
|
|
|
@@ -144,6 +163,9 @@ export class OrdersTestFactory {
|
|
|
stock: 100,
|
|
|
lowestBuy: 1,
|
|
|
createdBy,
|
|
|
+ categoryId1: testCategory.id, // 使用真实创建的分类ID
|
|
|
+ categoryId2: testCategory.id,
|
|
|
+ categoryId3: testCategory.id,
|
|
|
...overrides
|
|
|
});
|
|
|
return await goodsRepository.save(goods);
|