|
@@ -171,11 +171,13 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.data).toHaveLength(2);
|
|
|
|
|
- // 价格降序排列:220 > 210
|
|
|
|
|
- expect(data.data[0].price).toBe(220.00);
|
|
|
|
|
- expect(data.data[1].price).toBe(210.00);
|
|
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.data).toHaveLength(2);
|
|
|
|
|
+ // 价格降序排列:220 > 210
|
|
|
|
|
+ expect(data.data[0].price).toBe(220.00);
|
|
|
|
|
+ expect(data.data[1].price).toBe(210.00);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -205,10 +207,12 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.id).toBe(normalGoods.id);
|
|
|
|
|
- expect(data.spuId).toBe(0);
|
|
|
|
|
- expect(data.spuName).toBeNull();
|
|
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.id).toBe(normalGoods.id);
|
|
|
|
|
+ expect(data.spuId).toBe(0);
|
|
|
|
|
+ expect(data.spuName).toBeNull();
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该拒绝将子商品设为父商品', async () => {
|
|
it('应该拒绝将子商品设为父商品', async () => {
|
|
@@ -221,9 +225,11 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(400);
|
|
expect(response.status).toBe(400);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.code).toBe(400);
|
|
|
|
|
- expect(data.message).toContain('子商品不能设为父商品');
|
|
|
|
|
|
|
+ if (response.status === 400) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.code).toBe(400);
|
|
|
|
|
+ expect(data.message).toContain('子商品不能设为父商品');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该验证商品是否存在', async () => {
|
|
it('应该验证商品是否存在', async () => {
|
|
@@ -236,9 +242,11 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(response.status).toBe(404);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.code).toBe(404);
|
|
|
|
|
- expect(data.message).toContain('商品不存在');
|
|
|
|
|
|
|
+ if (response.status === 404) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.code).toBe(404);
|
|
|
|
|
+ expect(data.message).toContain('商品不存在');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -253,15 +261,17 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.id).toBe(childGoods1.id);
|
|
|
|
|
- expect(data.spuId).toBe(0);
|
|
|
|
|
- expect(data.spuName).toBeNull();
|
|
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.id).toBe(childGoods1.id);
|
|
|
|
|
+ expect(data.spuId).toBe(0);
|
|
|
|
|
+ expect(data.spuName).toBeNull();
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该拒绝解除非子商品的父子关系', async () => {
|
|
it('应该拒绝解除非子商品的父子关系', async () => {
|
|
|
const response = await client[':id']['parent'].$delete({
|
|
const response = await client[':id']['parent'].$delete({
|
|
|
- param: { id: parentGoods.id.toString() }
|
|
|
|
|
|
|
+ param: { id: parentGoods.id }
|
|
|
}, {
|
|
}, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${adminToken}`
|
|
'Authorization': `Bearer ${adminToken}`
|
|
@@ -269,9 +279,11 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(400);
|
|
expect(response.status).toBe(400);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.code).toBe(400);
|
|
|
|
|
|
|
+ if (response.status === 400) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.code).toBe(400);
|
|
|
expect(data.message).toContain('该商品不是子商品');
|
|
expect(data.message).toContain('该商品不是子商品');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该验证商品是否存在', async () => {
|
|
it('应该验证商品是否存在', async () => {
|
|
@@ -284,9 +296,11 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(response.status).toBe(404);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.code).toBe(404);
|
|
|
|
|
|
|
+ if (response.status === 404) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.code).toBe(404);
|
|
|
expect(data.message).toContain('商品不存在');
|
|
expect(data.message).toContain('商品不存在');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -310,8 +324,9 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.success).toBe(true);
|
|
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.success).toBe(true);
|
|
|
expect(data.count).toBe(3);
|
|
expect(data.count).toBe(3);
|
|
|
expect(data.children).toHaveLength(3);
|
|
expect(data.children).toHaveLength(3);
|
|
|
|
|
|
|
@@ -325,6 +340,7 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
expect(child.spuId).toBe(parentGoods.id);
|
|
expect(child.spuId).toBe(parentGoods.id);
|
|
|
expect(child.spuName).toBe(parentGoods.name);
|
|
expect(child.spuName).toBe(parentGoods.name);
|
|
|
});
|
|
});
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该验证父商品是否存在', async () => {
|
|
it('应该验证父商品是否存在', async () => {
|
|
@@ -344,9 +360,11 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(response.status).toBe(404);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.code).toBe(404);
|
|
|
|
|
|
|
+ if (response.status === 404) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.code).toBe(404);
|
|
|
expect(data.message).toContain('父商品不存在');
|
|
expect(data.message).toContain('父商品不存在');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该验证父商品必须是父商品', async () => {
|
|
it('应该验证父商品必须是父商品', async () => {
|
|
@@ -367,9 +385,11 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(400);
|
|
expect(response.status).toBe(400);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.code).toBe(400);
|
|
|
|
|
|
|
+ if (response.status === 400) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.code).toBe(400);
|
|
|
expect(data.message).toContain('只能为父商品创建子商品');
|
|
expect(data.message).toContain('只能为父商品创建子商品');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该验证规格数据有效性', async () => {
|
|
it('应该验证规格数据有效性', async () => {
|
|
@@ -389,9 +409,11 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(400);
|
|
expect(response.status).toBe(400);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.code).toBe(400);
|
|
|
|
|
|
|
+ if (response.status === 400) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.code).toBe(400);
|
|
|
expect(data.message).toContain('规格名称不能为空');
|
|
expect(data.message).toContain('规格名称不能为空');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该继承父商品的分类和其他信息', async () => {
|
|
it('应该继承父商品的分类和其他信息', async () => {
|
|
@@ -411,8 +433,9 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.success).toBe(true);
|
|
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.success).toBe(true);
|
|
|
expect(data.count).toBe(1);
|
|
expect(data.count).toBe(1);
|
|
|
|
|
|
|
|
const child = data.children[0];
|
|
const child = data.children[0];
|
|
@@ -422,6 +445,7 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
expect(child.supplierId).toBe(parentGoods.supplierId);
|
|
expect(child.supplierId).toBe(parentGoods.supplierId);
|
|
|
expect(child.merchantId).toBe(parentGoods.merchantId);
|
|
expect(child.merchantId).toBe(parentGoods.merchantId);
|
|
|
expect(child.goodsType).toBe(parentGoods.goodsType);
|
|
expect(child.goodsType).toBe(parentGoods.goodsType);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -437,9 +461,8 @@ describe('管理员父子商品管理API集成测试', () => {
|
|
|
|
|
|
|
|
it('应该验证租户隔离', async () => {
|
|
it('应该验证租户隔离', async () => {
|
|
|
// 创建另一个租户的用户
|
|
// 创建另一个租户的用户
|
|
|
- const otherTenantUser = await testFactory.createTestUser();
|
|
|
|
|
- otherTenantUser.tenantId = 2; // 不同租户
|
|
|
|
|
- await testFactory.dataSource.getRepository(UserEntityMt).save(otherTenantUser);
|
|
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+ const otherTenantUser = await testFactory.createTestUser(2); // 不同租户
|
|
|
|
|
|
|
|
const otherTenantToken = JWTUtil.generateToken({
|
|
const otherTenantToken = JWTUtil.generateToken({
|
|
|
id: otherTenantUser.id,
|
|
id: otherTenantUser.id,
|