Skip to content

Commit

Permalink
Revert "feat/CXSPA-7935:Modify the OCC API endpoint for SPA consumes(#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelfras authored Aug 23, 2024
1 parent a6acf89 commit 9648375
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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,11 +22,6 @@ 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,15 +233,16 @@ describe('OccUserProfileAdapter', () => {
.subscribe((result) => expect(result).toEqual(''));

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

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

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

let result: Object;

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

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

expect(occEndpointsService.buildUrl).toHaveBeenCalledWith(
'userUpdateLoginId',
{ urlParams: { userId } }
);
expect(mockReq.cancelled).toBeFalsy();
expect(mockReq.request.body).toEqual({
newLoginId: newUserId,
password: currentPassword,
});

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

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

let result: Object;

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

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

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

expect(mockReq.cancelled).toBeFalsy();
expect(mockReq.request.body).toEqual({
oldPassword: oldPassword,
newPassword: newPassword,
});
mockReq.flush('');
expect(result).toEqual('');
});
});

Expand Down
39 changes: 23 additions & 16 deletions feature-libs/user/profile/occ/adapters/occ-user-profile.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ export class OccUserProfileAdapter implements UserProfileAdapter {
}

requestForgotPasswordEmail(userEmailAddress: string): Observable<unknown> {
const url = this.occEndpoints.buildUrl('userRestoreToken');
const body = { loginId: userEmailAddress };
let headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);
const url = this.occEndpoints.buildUrl('userForgotPassword');
const httpParams: HttpParams = new HttpParams().set(
'userId',
userEmailAddress
);
let headers = new HttpHeaders({
...CONTENT_TYPE_URLENCODED_HEADER,
});
headers = InterceptorUtil.createHeader(USE_CLIENT_TOKEN, true, headers);
return this.http.post(url, body, { headers }).pipe(
return this.http.post(url, httpParams, { headers }).pipe(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
Expand Down Expand Up @@ -129,12 +134,13 @@ export class OccUserProfileAdapter implements UserProfileAdapter {
const url = this.occEndpoints.buildUrl('userUpdateLoginId', {
urlParams: { userId },
});
const body = {
newLoginId: newUserId,
password: currentPassword,
};
const headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);
return this.http.post(url, body, { headers }).pipe(
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(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
Expand All @@ -149,12 +155,13 @@ export class OccUserProfileAdapter implements UserProfileAdapter {
const url = this.occEndpoints.buildUrl('userUpdatePassword', {
urlParams: { userId },
});
const body = {
oldPassword: oldPassword,
newPassword: newPassword,
};
const headers = new HttpHeaders(CONTENT_TYPE_JSON_HEADER);
return this.http.post(url, body, { headers }).pipe(
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(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
Expand Down

0 comments on commit 9648375

Please sign in to comment.