|
|
@@ -40,8 +40,10 @@ describe('支付API集成测试', () => {
|
|
|
const userService = new UserService(dataSource);
|
|
|
const authService = new AuthService(userService);
|
|
|
|
|
|
- // 创建测试用户
|
|
|
- testUser = await TestDataFactory.createTestUser(dataSource);
|
|
|
+ // 创建测试用户,确保有openid字段
|
|
|
+ testUser = await TestDataFactory.createTestUser(dataSource, {
|
|
|
+ openid: 'oJy1-16IIG18XZLl7G32k1hHMUFg'
|
|
|
+ });
|
|
|
|
|
|
// 生成测试用户的token
|
|
|
testToken = authService.generateToken(testUser);
|
|
|
@@ -91,8 +93,7 @@ describe('支付API集成测试', () => {
|
|
|
json: {
|
|
|
orderId: testOrder.id,
|
|
|
totalAmount: 20000, // 200元,单位分
|
|
|
- description: '测试支付订单',
|
|
|
- openid: 'oJy1-16IIG18XZLl7G32k1hHMUFg'
|
|
|
+ description: '测试支付订单'
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -199,6 +200,38 @@ describe('支付API集成测试', () => {
|
|
|
expect(result.message).toContain('订单支付状态不正确');
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ it('应该拒绝没有openid的用户支付', async () => {
|
|
|
+ // 创建没有openid的测试用户
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const userService = new UserService(dataSource);
|
|
|
+ const authService = new AuthService(userService);
|
|
|
+
|
|
|
+ const userWithoutOpenid = await TestDataFactory.createTestUser(dataSource, {
|
|
|
+ openid: null
|
|
|
+ });
|
|
|
+
|
|
|
+ const tokenWithoutOpenid = authService.generateToken(userWithoutOpenid);
|
|
|
+
|
|
|
+ const response = await client.payment.$post({
|
|
|
+ json: {
|
|
|
+ orderId: testOrder.id,
|
|
|
+ totalAmount: 20000,
|
|
|
+ description: '测试支付订单'
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${tokenWithoutOpenid}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(400);
|
|
|
+ if (response.status === 400) {
|
|
|
+ const result = await response.json();
|
|
|
+ expect(result.message).toContain('用户未绑定微信小程序');
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('POST /payment/callback - 支付回调', () => {
|
|
|
@@ -297,8 +330,7 @@ describe('支付API集成测试', () => {
|
|
|
json: {
|
|
|
orderId: testOrder.id,
|
|
|
totalAmount: 20000,
|
|
|
- description: '测试支付订单',
|
|
|
- openid: 'oJy1-16IIG18XZLl7G32k1hHMUFg'
|
|
|
+ description: '测试支付订单'
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -326,8 +358,7 @@ describe('支付API集成测试', () => {
|
|
|
json: {
|
|
|
orderId: testOrder.id,
|
|
|
totalAmount: 20000,
|
|
|
- description: '测试支付订单',
|
|
|
- openid: 'oJy1-16IIG18XZLl7G32k1hHMUFg'
|
|
|
+ description: '测试支付订单'
|
|
|
},
|
|
|
},
|
|
|
{
|