Browse Source

✅ test(auth): 优化登录失败测试用例

- 修正认证失败状态码检查,确保只返回401而非500
- 更新错误消息断言,使用"用户名或密码错误"替代英文消息
- 统一两种登录失败场景的测试逻辑和断言方式
yourname 2 months ago
parent
commit
58675c9767
1 changed files with 8 additions and 8 deletions
  1. 8 8
      src/server/api/auth/__tests__/auth.integration.test.ts

+ 8 - 8
src/server/api/auth/__tests__/auth.integration.test.ts

@@ -88,11 +88,11 @@ describe('认证API集成测试 (使用hono/testing)', () => {
         json: loginData
       });
 
-      // 根据实际实现,认证失败可能返回500而不是401
-      expect([401, 500]).toContain(response.status);
-      if (response.status === 500) {
+      // 认证失败应该返回401
+      expect(response.status).toBe(401);
+      if (response.status === 401){
         const responseData = await response.json();
-        expect(responseData.message).toContain('Invalid password');
+        expect(responseData.message).toContain('用户名或密码错误');
       }
     });
 
@@ -106,11 +106,11 @@ describe('认证API集成测试 (使用hono/testing)', () => {
         json: loginData
       });
 
-      // 根据实际实现,认证失败可能返回500而不是401
-      expect([401, 500]).toContain(response.status);
-      if (response.status === 500) {
+      // 认证失败应该返回401
+      expect(response.status).toBe(401);
+      if (response.status === 401){
         const responseData = await response.json();
-        expect(responseData.message).toContain('User not found');
+        expect(responseData.message).toContain('用户名或密码错误');
       }
     });