|
|
@@ -23,6 +23,7 @@ describe('用户商品管理API集成测试', () => {
|
|
|
let testCategory: GoodsCategory;
|
|
|
let testSupplier: Supplier;
|
|
|
let testMerchant: Merchant;
|
|
|
+ let testFile: File;
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
// 创建测试客户端
|
|
|
@@ -100,6 +101,20 @@ describe('用户商品管理API集成测试', () => {
|
|
|
createdBy: testUser.id
|
|
|
});
|
|
|
await merchantRepository.save(testMerchant);
|
|
|
+
|
|
|
+ // 创建测试文件
|
|
|
+ const fileRepository = dataSource.getRepository(File);
|
|
|
+ testFile = fileRepository.create({
|
|
|
+ name: 'test_image.jpg',
|
|
|
+ type: 'image/jpeg',
|
|
|
+ size: 102400,
|
|
|
+ path: 'images/test_image.jpg',
|
|
|
+ uploadUserId: testUser.id,
|
|
|
+ uploadTime: new Date(),
|
|
|
+ createdAt: new Date(),
|
|
|
+ updatedAt: new Date()
|
|
|
+ });
|
|
|
+ await fileRepository.save(testFile);
|
|
|
});
|
|
|
|
|
|
describe('GET /goods', () => {
|
|
|
@@ -118,6 +133,7 @@ describe('用户商品管理API集成测试', () => {
|
|
|
goodsType: 1,
|
|
|
supplierId: testSupplier.id,
|
|
|
merchantId: testMerchant.id,
|
|
|
+ imageFileId: testFile.id,
|
|
|
state: 1,
|
|
|
stock: 100,
|
|
|
lowestBuy: 1,
|
|
|
@@ -135,6 +151,7 @@ describe('用户商品管理API集成测试', () => {
|
|
|
goodsType: 1,
|
|
|
supplierId: testSupplier.id,
|
|
|
merchantId: testMerchant.id,
|
|
|
+ imageFileId: testFile.id,
|
|
|
state: 1,
|
|
|
stock: 50,
|
|
|
lowestBuy: 1,
|
|
|
@@ -153,6 +170,7 @@ describe('用户商品管理API集成测试', () => {
|
|
|
goodsType: 1,
|
|
|
supplierId: testSupplier.id,
|
|
|
merchantId: testMerchant.id,
|
|
|
+ imageFileId: testFile.id,
|
|
|
state: 1,
|
|
|
stock: 30,
|
|
|
lowestBuy: 1,
|
|
|
@@ -551,12 +569,18 @@ describe('用户商品管理API集成测试', () => {
|
|
|
expect(response.status).toBe(200);
|
|
|
const data = await response.json();
|
|
|
|
|
|
- // 验证只返回测试用户的商品
|
|
|
- const userGoodsInResponse = data.data.filter((goods: any) => goods.createdBy === testUser.id);
|
|
|
- const otherUserGoodsInResponse = data.data.filter((goods: any) => goods.createdBy === otherUser.id);
|
|
|
+ // 类型检查确保data属性存在
|
|
|
+ if ('data' in data && Array.isArray(data.data)) {
|
|
|
+ // 验证只返回测试用户的商品
|
|
|
+ const userGoodsInResponse = data.data.filter((goods: any) => goods.createdBy === testUser.id);
|
|
|
+ const otherUserGoodsInResponse = data.data.filter((goods: any) => goods.createdBy === otherUser.id);
|
|
|
|
|
|
- expect(userGoodsInResponse.length).toBeGreaterThan(0);
|
|
|
- expect(otherUserGoodsInResponse.length).toBe(0);
|
|
|
+ expect(userGoodsInResponse.length).toBeGreaterThan(0);
|
|
|
+ expect(otherUserGoodsInResponse.length).toBe(0);
|
|
|
+ } else {
|
|
|
+ // 如果响应是错误格式,应该失败
|
|
|
+ expect(data).toHaveProperty('data');
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
});
|