|
|
@@ -142,6 +142,7 @@ describe('多租户用户订单管理API集成测试', () => {
|
|
|
it('不应该访问其他用户的订单详情', async () => {
|
|
|
// 创建其他用户的订单
|
|
|
const otherUserOrder = await testFactory.createTestOrder(otherUser.id, { tenantId: 1 });
|
|
|
+ console.debug('创建的订单:', { id: otherUserOrder.id, userId: otherUserOrder.userId, tenantId: otherUserOrder.tenantId });
|
|
|
|
|
|
// 使用当前用户尝试访问其他用户的订单
|
|
|
const response = await client[':id'].$get({
|
|
|
@@ -152,8 +153,14 @@ describe('多租户用户订单管理API集成测试', () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 应该返回404,因为无权访问其他用户的订单(安全考虑,不暴露存在性)
|
|
|
- expect(response.status).toBe(404);
|
|
|
+ // 应该返回403,因为无权访问其他用户的订单
|
|
|
+ console.debug('响应状态码:', response.status);
|
|
|
+ expect(response.status).toBe(403);
|
|
|
+ if (response.status === 403) {
|
|
|
+ const result = await response.json();
|
|
|
+ console.debug('响应内容:', result);
|
|
|
+ expect(result.message).toBe('没有权限访问该资源');
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -163,22 +170,22 @@ describe('多租户用户订单管理API集成测试', () => {
|
|
|
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 testGoods = await testFactory.createTestGoods(testUser.id, {
|
|
|
+ tenantId: 1,
|
|
|
+ merchantId: testMerchant.id,
|
|
|
+ supplierId: testSupplier.id
|
|
|
+ });
|
|
|
|
|
|
const orderData = {
|
|
|
- orderNo: `ORD_${Date.now()}`,
|
|
|
- amount: 100.00,
|
|
|
- payAmount: 95.00,
|
|
|
- discountAmount: 5.00,
|
|
|
- merchantId: testMerchant.id,
|
|
|
- supplierId: testSupplier.id,
|
|
|
addressId: testDeliveryAddress.id,
|
|
|
- orderType: 1,
|
|
|
- payType: 1,
|
|
|
- payState: 0,
|
|
|
- state: 0
|
|
|
+ productOwn: '自营',
|
|
|
+ consumeFrom: '积分兑换',
|
|
|
+ products: [
|
|
|
+ { id: testGoods.id, num: 2 }
|
|
|
+ ]
|
|
|
};
|
|
|
|
|
|
- const response = await client.index.$post({
|
|
|
+ const response = await client['create-order'].$post({
|
|
|
json: orderData
|
|
|
}, {
|
|
|
headers: {
|
|
|
@@ -186,13 +193,21 @@ describe('多租户用户订单管理API集成测试', () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ 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();
|
|
|
|
|
|
- // 验证租户ID已正确设置
|
|
|
- expect(createdOrder.tenantId).toBe(1);
|
|
|
- expect(createdOrder.userId).toBe(testUser.id);
|
|
|
+ // 验证订单创建成功
|
|
|
+ expect(createdOrder.success).toBe(true);
|
|
|
+ expect(createdOrder.orderId).toBeGreaterThan(0);
|
|
|
+ expect(createdOrder.orderNo).toBeDefined();
|
|
|
+ expect(createdOrder.amount).toBeGreaterThan(0);
|
|
|
+ expect(createdOrder.payAmount).toBeGreaterThan(0);
|
|
|
}
|
|
|
});
|
|
|
});
|