|
@@ -82,6 +82,32 @@ describe('人才用户认证API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('人才用户登录端点测试 (POST /auth/login)', () => {
|
|
describe('人才用户登录端点测试 (POST /auth/login)', () => {
|
|
|
|
|
+ it('应该使用手机号和正确密码成功登录', async () => {
|
|
|
|
|
+ const loginData = {
|
|
|
|
|
+ identifier: '13800138001', // 测试用户的手机号
|
|
|
|
|
+ password: 'TalentPass123!'
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const response = await client.login.$post({
|
|
|
|
|
+ json: loginData
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(200);
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const responseData = await response.json();
|
|
|
|
|
+ expect(responseData).toHaveProperty('token');
|
|
|
|
|
+ expect(responseData).toHaveProperty('user');
|
|
|
|
|
+ expect(responseData.user.username).toBe('talent_user');
|
|
|
|
|
+ expect(responseData.user.userType).toBe(UserType.TALENT);
|
|
|
|
|
+ expect(responseData.user.personId).toBe(testPerson.id);
|
|
|
|
|
+ expect(responseData.user.phone).toBe('13800138001');
|
|
|
|
|
+ expect(responseData.user.personInfo).toBeDefined();
|
|
|
|
|
+ expect(responseData.user.personInfo.name).toBe('张三');
|
|
|
|
|
+ expect(typeof responseData.token).toBe('string');
|
|
|
|
|
+ expect(responseData.token.length).toBeGreaterThan(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
it('应该使用身份证号和正确密码成功登录', async () => {
|
|
it('应该使用身份证号和正确密码成功登录', async () => {
|
|
|
const loginData = {
|
|
const loginData = {
|
|
|
identifier: testIdCard,
|
|
identifier: testIdCard,
|
|
@@ -142,7 +168,7 @@ describe('人才用户认证API集成测试', () => {
|
|
|
expect(response.status).toBe(401);
|
|
expect(response.status).toBe(401);
|
|
|
if (response.status === 401) {
|
|
if (response.status === 401) {
|
|
|
const responseData = await response.json();
|
|
const responseData = await response.json();
|
|
|
- expect(responseData.message).toContain('身份证号或密码错误');
|
|
|
|
|
|
|
+ expect(responseData.message).toContain('账号或密码错误');
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -159,7 +185,24 @@ describe('人才用户认证API集成测试', () => {
|
|
|
expect(response.status).toBe(401);
|
|
expect(response.status).toBe(401);
|
|
|
if (response.status === 401) {
|
|
if (response.status === 401) {
|
|
|
const responseData = await response.json();
|
|
const responseData = await response.json();
|
|
|
- expect(responseData.message).toContain('身份证号或密码错误');
|
|
|
|
|
|
|
+ expect(responseData.message).toContain('账号或密码错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('应该拒绝不存在的手机号登录', async () => {
|
|
|
|
|
+ const loginData = {
|
|
|
|
|
+ identifier: '19999999999', // 不存在的手机号
|
|
|
|
|
+ password: 'TalentPass123!'
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const response = await client.login.$post({
|
|
|
|
|
+ json: loginData
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(response.status).toBe(401);
|
|
|
|
|
+ if (response.status === 401) {
|
|
|
|
|
+ const responseData = await response.json();
|
|
|
|
|
+ expect(responseData.message).toContain('账号或密码错误');
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -189,7 +232,7 @@ describe('人才用户认证API集成测试', () => {
|
|
|
const responseData = await response.json();
|
|
const responseData = await response.json();
|
|
|
// 由于getTalentUserByIdentifier只查询TALENT类型用户,非人才用户会被视为不存在
|
|
// 由于getTalentUserByIdentifier只查询TALENT类型用户,非人才用户会被视为不存在
|
|
|
// 这是更安全的做法,不透露用户存在性信息
|
|
// 这是更安全的做法,不透露用户存在性信息
|
|
|
- expect(responseData.message).toContain('身份证号或密码错误');
|
|
|
|
|
|
|
+ expect(responseData.message).toContain('账号或密码错误');
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|