|
|
@@ -273,6 +273,122 @@ describe('多租户用户订单管理API集成测试', () => {
|
|
|
expect(createdOrder.payAmount).toBeGreaterThan(0);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ it('应该为子商品订单快照生成包含父商品名称的商品名称', async () => {
|
|
|
+ // 创建必要的关联实体
|
|
|
+ const testSupplier = await testFactory.createTestSupplier(testUser.id, { tenantId: 1 });
|
|
|
+ const testMerchant = await testFactory.createTestMerchant(testUser.id, { tenantId: 1 });
|
|
|
+ const testDeliveryAddress = await testFactory.createTestDeliveryAddress(testUser.id, { tenantId: 1 });
|
|
|
+
|
|
|
+ // 创建父商品
|
|
|
+ const parentGoods = await testFactory.createTestGoods(testUser.id, {
|
|
|
+ tenantId: 1,
|
|
|
+ merchantId: testMerchant.id,
|
|
|
+ supplierId: testSupplier.id,
|
|
|
+ name: '连衣裙'
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建子商品(规格商品)
|
|
|
+ const childGoods = await testFactory.createTestGoods(testUser.id, {
|
|
|
+ tenantId: 1,
|
|
|
+ merchantId: testMerchant.id,
|
|
|
+ supplierId: testSupplier.id,
|
|
|
+ name: '红色 大码',
|
|
|
+ spuId: parentGoods.id
|
|
|
+ });
|
|
|
+
|
|
|
+ const orderData = {
|
|
|
+ addressId: testDeliveryAddress.id,
|
|
|
+ productOwn: '自营',
|
|
|
+ consumeFrom: '积分兑换',
|
|
|
+ products: [
|
|
|
+ { id: childGoods.id, num: 1 }
|
|
|
+ ]
|
|
|
+ };
|
|
|
+
|
|
|
+ const response = await client['create-order'].$post({
|
|
|
+ json: orderData
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${userToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ console.debug('子商品订单创建响应状态码:', response.status);
|
|
|
+ if (response.status !== 201) {
|
|
|
+ const errorResult = await response.json();
|
|
|
+ console.debug('子商品订单创建错误响应:', errorResult);
|
|
|
+ }
|
|
|
+ expect(response.status).toBe(201);
|
|
|
+ if (response.status === 201) {
|
|
|
+ const createdOrder = await response.json();
|
|
|
+
|
|
|
+ // 验证订单创建成功
|
|
|
+ expect(createdOrder.success).toBe(true);
|
|
|
+ expect(createdOrder.orderId).toBeGreaterThan(0);
|
|
|
+
|
|
|
+ // 查询订单商品明细,验证商品名称格式
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const orderGoods = await dataSource.getRepository(OrderGoodsMt).find({
|
|
|
+ where: { orderId: createdOrder.orderId, tenantId: 1 }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(orderGoods).toHaveLength(1);
|
|
|
+ expect(orderGoods[0].goodsName).toBe('连衣裙 红色 大码');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ it('应该为单规格商品保持原有商品名称', async () => {
|
|
|
+ // 创建必要的关联实体
|
|
|
+ const testSupplier = await testFactory.createTestSupplier(testUser.id, { tenantId: 1 });
|
|
|
+ const testMerchant = await testFactory.createTestMerchant(testUser.id, { tenantId: 1 });
|
|
|
+ const testDeliveryAddress = await testFactory.createTestDeliveryAddress(testUser.id, { tenantId: 1 });
|
|
|
+
|
|
|
+ // 创建单规格商品(spuId = 0)
|
|
|
+ const singleSpecGoods = await testFactory.createTestGoods(testUser.id, {
|
|
|
+ tenantId: 1,
|
|
|
+ merchantId: testMerchant.id,
|
|
|
+ supplierId: testSupplier.id,
|
|
|
+ name: '单规格商品',
|
|
|
+ spuId: 0
|
|
|
+ });
|
|
|
+
|
|
|
+ const orderData = {
|
|
|
+ addressId: testDeliveryAddress.id,
|
|
|
+ productOwn: '自营',
|
|
|
+ consumeFrom: '积分兑换',
|
|
|
+ products: [
|
|
|
+ { id: singleSpecGoods.id, num: 1 }
|
|
|
+ ]
|
|
|
+ };
|
|
|
+
|
|
|
+ const response = await client['create-order'].$post({
|
|
|
+ json: orderData
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${userToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ console.debug('单规格商品订单创建响应状态码:', response.status);
|
|
|
+ expect(response.status).toBe(201);
|
|
|
+ if (response.status === 201) {
|
|
|
+ const createdOrder = await response.json();
|
|
|
+
|
|
|
+ // 验证订单创建成功
|
|
|
+ expect(createdOrder.success).toBe(true);
|
|
|
+ expect(createdOrder.orderId).toBeGreaterThan(0);
|
|
|
+
|
|
|
+ // 查询订单商品明细,验证商品名称保持不变
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const orderGoods = await dataSource.getRepository(OrderGoodsMt).find({
|
|
|
+ where: { orderId: createdOrder.orderId, tenantId: 1 }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(orderGoods).toHaveLength(1);
|
|
|
+ expect(orderGoods[0].goodsName).toBe('单规格商品');
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('取消订单功能验证', () => {
|