Skip to content

Commit be527fa

Browse files
committed
feat: Implement loginUnsecure method and add corresponding tests for payload validation
1 parent cd72974 commit be527fa

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

packages/user/src/auth-services.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,28 @@ export class AuthService {
134134
* @param loginData Login credentials (shared domain types recommended)
135135
*/
136136
async login(loginData: { username: string; password: string; rememberMe?: boolean }): Promise<RestApiResult> {
137-
const data = {
138-
UserName: loginData.username,
139-
Password: loginData.password,
140-
RememberMe: loginData.rememberMe,
141-
Email: '',
142-
ReturnUrl: '',
143-
};
144-
const message = this.config.encryptAES(JSON.stringify(data));
137+
return this.loginUnsecure({
138+
userName: loginData.username,
139+
password: loginData.password,
140+
rememberMe: loginData.rememberMe,
141+
email: '',
142+
phoneNumber: '',
143+
returnUrl: ''
144+
});
145+
}
146+
147+
async loginUnsecure(loginData: {
148+
email: string;
149+
userName: string;
150+
phoneNumber: string;
151+
password: string;
152+
rememberMe: boolean;
153+
returnUrl: string;
154+
}): Promise<RestApiResult> {
145155
const req = {
146156
method: 'POST',
147-
url: '/account/login',
148-
data: JSON.stringify({ message }),
157+
url: '/api/v2/rest/auth/user/login-unsecure',
158+
data: JSON.stringify(loginData),
149159
};
150160
const resp = await this.config.getRestApiResult(req, true);
151161
if (resp.isSucceed) {

packages/user/tests/auth-services.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ describe('AuthService', () => {
5151
expect(config.updateAuthData).toHaveBeenCalled();
5252
});
5353

54+
it('should call loginUnsecure with correct payload', async () => {
55+
await service.loginUnsecure({
56+
57+
userName: 'user',
58+
phoneNumber: '123456789',
59+
password: 'pass',
60+
rememberMe: true,
61+
returnUrl: '/home'
62+
});
63+
expect(config.getRestApiResult).toHaveBeenCalledWith({
64+
method: 'POST',
65+
url: '/api/v2/rest/auth/user/login-unsecure',
66+
data: JSON.stringify({
67+
68+
userName: 'user',
69+
phoneNumber: '123456789',
70+
password: 'pass',
71+
rememberMe: true,
72+
returnUrl: '/home'
73+
})
74+
}, true);
75+
expect(config.updateAuthData).toHaveBeenCalled();
76+
});
77+
5478
it('should call logOut and removeItem', async () => {
5579
await service.logOut();
5680
expect(config.localStorage?.removeItem).toHaveBeenCalledWith('authorizationData');

0 commit comments

Comments
 (0)