Skip to content

Commit

Permalink
fixup! fix: basket promotion code assignment gets lost after registra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
dhhyi committed Jan 12, 2021
1 parent e2eeb5f commit ef4c0bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
15 changes: 9 additions & 6 deletions src/app/core/services/user/user.service.spec.ts
Expand Up @@ -36,11 +36,12 @@ describe('User Service', () => {
describe('SignIn a user', () => {
it('should login a user when correct credentials are entered', done => {
const loginDetail = { login: 'patricia@test.intershop.de', password: '!InterShop00!' };
when(apiServiceMock.get(anything(), anything())).thenReturn(of({ customerNo: 'PC' } as Customer));
when(apiServiceMock.get('customers/-', anything())).thenReturn(of({ customerNo: 'PC' } as Customer));
when(apiServiceMock.get('privatecustomers/-')).thenReturn(of({ customerNo: 'PC' } as Customer));

userService.signinUser(loginDetail).subscribe(data => {
const [, options] = capture<{}, { headers: HttpHeaders }>(apiServiceMock.get).last();
const headers = options.headers;
const [, options] = capture<{}, { headers: HttpHeaders }>(apiServiceMock.get).beforeLast();
const headers = options?.headers;
expect(headers).toBeTruthy();
expect(headers.get('Authorization')).toEqual('BASIC cGF0cmljaWFAdGVzdC5pbnRlcnNob3AuZGU6IUludGVyU2hvcDAwIQ==');

Expand All @@ -51,11 +52,12 @@ describe('User Service', () => {

it('should login a private user when correct credentials are entered', done => {
const loginDetail = { login: 'patricia@test.intershop.de', password: '!InterShop00!' };
when(apiServiceMock.get(anything(), anything())).thenReturn(of({ customerNo: 'PC' } as Customer));
when(apiServiceMock.get('customers/-', anything())).thenReturn(of({ customerNo: 'PC' } as Customer));
when(apiServiceMock.get('privatecustomers/-')).thenReturn(of({ customerNo: 'PC' } as Customer));

userService.signinUser(loginDetail).subscribe(() => {
verify(apiServiceMock.get(`customers/-`, anything())).once();
verify(apiServiceMock.get(`privatecustomers/-`, anything())).once();
verify(apiServiceMock.get(`privatecustomers/-`)).once();
done();
});
});
Expand Down Expand Up @@ -120,6 +122,7 @@ describe('User Service', () => {
it("should create a new individual user when 'createUser' is called", done => {
when(apiServiceMock.post(anyString(), anything(), anything())).thenReturn(of({}));
when(apiServiceMock.get(anything(), anything())).thenReturn(of({ customerNo: 'PC' } as Customer));
when(apiServiceMock.get(anything())).thenReturn(of({ customerNo: 'PC' } as Customer));

const payload = {
customer: { customerNo: '4711', isBusinessCustomer: false } as Customer,
Expand All @@ -131,7 +134,7 @@ describe('User Service', () => {
userService.createUser(payload).subscribe(() => {
verify(apiServiceMock.post('privatecustomers', anything(), anything())).once();
verify(apiServiceMock.get('customers/-', anything())).once();
verify(apiServiceMock.get('privatecustomers/-', anything())).once();
verify(apiServiceMock.get('privatecustomers/-')).once();
done();
});
});
Expand Down
38 changes: 14 additions & 24 deletions src/app/core/services/user/user.service.ts
Expand Up @@ -54,32 +54,22 @@ export class UserService {
'BASIC ' + b64u.toBase64(b64u.encode(`${loginCredentials.login}:${loginCredentials.password}`))
);

return this.apiService
.get<CustomerData>('customers/-', { headers })
.pipe(
withLatestFrom(this.appFacade.isAppTypeREST$),
concatMap(([data, isAppTypeRest]) =>
// ToDo: #IS-30018 use the customer type for this decision
isAppTypeRest && !data.companyName
? this.apiService.get<CustomerData>('privatecustomers/-', { headers })
: of(data)
),
map(CustomerMapper.mapLoginData)
);
return this.fetchUser({ headers });
}

signinUserByToken(): Observable<CustomerUserType> {
return this.apiService
.get<CustomerData>('customers/-', { skipApiErrorHandling: true, runExclusively: true })
.pipe(
withLatestFrom(this.appFacade.isAppTypeREST$),
concatMap(([data, isAppTypeRest]) =>
// ToDo: #IS-30018 use the customer type for this decision
isAppTypeRest && !data.companyName ? this.apiService.get<CustomerData>('privatecustomers/-') : of(data)
),
map(CustomerMapper.mapLoginData),
catchError(() => EMPTY)
);
return this.fetchUser({ skipApiErrorHandling: true, runExclusively: true }).pipe(catchError(() => EMPTY));
}

private fetchUser(options?: AvailableOptions): Observable<CustomerUserType> {
return this.apiService.get<CustomerData>('customers/-', options).pipe(
withLatestFrom(this.appFacade.isAppTypeREST$),
concatMap(([data, isAppTypeRest]) =>
// ToDo: #IS-30018 use the customer type for this decision
isAppTypeRest && !data.companyName ? this.apiService.get<CustomerData>('privatecustomers/-') : of(data)
),
map(CustomerMapper.mapLoginData)
);
}

/**
Expand Down Expand Up @@ -122,7 +112,7 @@ export class UserService {
.post<void>(AppFacade.getCustomerRestResource(body.customer.isBusinessCustomer, isAppTypeRest), newCustomer, {
captcha: pick(body, ['captcha', 'captchaAction']),
})
.pipe(concatMap(() => this.signinUser(body.credentials)))
.pipe(concatMap(() => this.fetchUser()))
)
);
}
Expand Down

1 comment on commit ef4c0bf

@github-actions
Copy link

Choose a reason for hiding this comment

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

Azure Demo Servers are available:

Please sign in to comment.