Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/CXSPA-7935:Modify the OCC API endpoint for SPA consumes(#19141) #19141

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const defaultOccUserProfileConfig: OccConfig = {
endpoints: {
userRegister: 'users',
userForgotPassword: 'forgottenpasswordtokens',
userRestoreToken: 'passwordRestoreToken',
userResetPassword: 'resetpassword',
userUpdateLoginId: 'users/${userId}/login',
userUpdatePassword: 'users/${userId}/password',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export interface UserProfileOccEndpoints {
*/
userForgotPassword?: string | OccEndpoint;

/**
* Request an email to reset the password
*/
userRestoreToken?: string | OccEndpoint;

/**
* Reset the password once the email is received.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,15 @@ describe('OccUserProfileAdapter', () => {
.subscribe((result) => expect(result).toEqual(''));

const mockReq = httpMock.expectOne((req) => {
return (
req.method === 'POST' &&
req.serializeBody() === `userId=${testUserId}`
);
return req.method === 'POST' && req.url === '/userRestoreToken';
});

expect(occEndpointsService.buildUrl).toHaveBeenCalledWith(
'userForgotPassword'
'userRestoreToken'
);

expect(mockReq.cancelled).toBeFalsy();
expect(mockReq.request.body).toEqual({ loginId: testUserId });
mockReq.flush('');
});
});
Expand Down Expand Up @@ -301,28 +300,24 @@ describe('OccUserProfileAdapter', () => {
const currentPassword = 'Qwe123!';
const newUserId = '[email protected]';

let result: Object;

occUserAdapter
.updateEmail(userId, currentPassword, newUserId)
.subscribe((value) => (result = value));
.subscribe();

const mockReq = httpMock.expectOne((req) => {
return (
req.method === 'PUT' &&
req.serializeBody() ===
`password=${currentPassword}&newLogin=${newUserId}`
);
return req.method === 'POST' && req.url === '/userUpdateLoginId';
});

expect(occEndpointsService.buildUrl).toHaveBeenCalledWith(
'userUpdateLoginId',
{ urlParams: { userId } }
);
expect(mockReq.cancelled).toBeFalsy();

expect(mockReq.request.body).toEqual({
newLoginId: newUserId,
password: currentPassword,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
password: currentPassword,
password: currentPassword

});
mockReq.flush('');
expect(result).toEqual('');
});
});

Expand All @@ -332,17 +327,12 @@ describe('OccUserProfileAdapter', () => {
const oldPassword = 'OldPass123!';
const newPassword = 'NewPass456!';

let result: Object;

occUserAdapter
.updatePassword(userId, oldPassword, newPassword)
.subscribe((value) => (result = value));
.subscribe();

const mockReq = httpMock.expectOne((req) => {
return (
req.method === 'PUT' &&
req.serializeBody() === `old=${oldPassword}&new=${newPassword}`
);
return req.method === 'POST' && req.url === '/userUpdatePassword';
});

expect(occEndpointsService.buildUrl).toHaveBeenCalledWith(
Expand All @@ -351,8 +341,11 @@ describe('OccUserProfileAdapter', () => {
);

expect(mockReq.cancelled).toBeFalsy();
expect(mockReq.request.body).toEqual({
oldPassword: oldPassword,
newPassword: newPassword,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
newPassword: newPassword,
newPassword: newPassword

});
mockReq.flush('');
expect(result).toEqual('');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,11 @@ export class OccUserProfileAdapter implements UserProfileAdapter {
}

requestForgotPasswordEmail(userEmailAddress: string): Observable<unknown> {
const url = this.occEndpoints.buildUrl('userForgotPassword');
const httpParams: HttpParams = new HttpParams().set(
'userId',
userEmailAddress
);
let headers = new HttpHeaders({
...CONTENT_TYPE_URLENCODED_HEADER,
});
const url = this.occEndpoints.buildUrl('userRestoreToken');
const body = { loginId: userEmailAddress };
let headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);
const headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);

headers = InterceptorUtil.createHeader(USE_CLIENT_TOKEN, true, headers);
return this.http.post(url, httpParams, { headers }).pipe(
return this.http.post(url, body, { headers }).pipe(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
Expand Down Expand Up @@ -134,13 +129,12 @@ export class OccUserProfileAdapter implements UserProfileAdapter {
const url = this.occEndpoints.buildUrl('userUpdateLoginId', {
urlParams: { userId },
});
const httpParams: HttpParams = new HttpParams()
.set('password', currentPassword)
.set('newLogin', newUserId);
const headers = new HttpHeaders({
...CONTENT_TYPE_URLENCODED_HEADER,
});
return this.http.put(url, httpParams, { headers }).pipe(
const body = {
newLoginId: newUserId,
password: currentPassword,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
password: currentPassword,
password: currentPassword

};
const headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);
return this.http.post(url, body, { headers }).pipe(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
Expand All @@ -155,13 +149,12 @@ export class OccUserProfileAdapter implements UserProfileAdapter {
const url = this.occEndpoints.buildUrl('userUpdatePassword', {
urlParams: { userId },
});
const httpParams: HttpParams = new HttpParams()
.set('old', oldPassword)
.set('new', newPassword);
const headers = new HttpHeaders({
...CONTENT_TYPE_URLENCODED_HEADER,
});
return this.http.put(url, httpParams, { headers }).pipe(
const body = {
oldPassword: oldPassword,
newPassword: newPassword,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
newPassword: newPassword,
newPassword: newPassword

};
const headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);
return this.http.post(url, body, { headers }).pipe(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
Expand Down
Loading