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

fix: basket promotion code assignment gets lost after registration #497

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Changes from 1 commit
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
Next Next commit
fix: basket promotion code assignment gets lost after registration
SGrueber committed Jan 11, 2021
commit b306b297aa55de0e8def09b641687b722055190c
5 changes: 4 additions & 1 deletion src/app/core/services/user/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -119,16 +119,19 @@ 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));

const payload = {
customer: { customerNo: '4711', isBusinessCustomer: false } as Customer,
address: {} as Address,
credentials: {} as Credentials,
credentials: { login: 'patricia@test.intershop.de', password: 'xyz' } as Credentials,
user: {} as User,
} as CustomerRegistrationType;

userService.createUser(payload).subscribe(() => {
verify(apiServiceMock.post('privatecustomers', anything(), anything())).once();
verify(apiServiceMock.get('customers/-', anything())).once();
verify(apiServiceMock.get('privatecustomers/-', anything())).once();
done();
});
});
12 changes: 5 additions & 7 deletions src/app/core/services/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ export class UserService {
* Create a new user for the given data.
* @param body The user data (customer, user, credentials, address) to create a new user.
*/
createUser(body: CustomerRegistrationType): Observable<void> {
createUser(body: CustomerRegistrationType): Observable<CustomerUserType> {
if (!body || !body.customer || !body.user || !body.credentials || !body.address) {
return throwError('createUser() called without required body data');
}
@@ -118,13 +118,11 @@ export class UserService {
return this.appFacade.isAppTypeREST$.pipe(
first(),
concatMap(isAppTypeRest =>
this.apiService.post<void>(
AppFacade.getCustomerRestResource(body.customer.isBusinessCustomer, isAppTypeRest),
newCustomer,
{
this.apiService
.post<void>(AppFacade.getCustomerRestResource(body.customer.isBusinessCustomer, isAppTypeRest), newCustomer, {
captcha: pick(body, ['captcha', 'captchaAction']),
}
)
})
.pipe(concatMap(() => this.signinUser(body.credentials)))
dhhyi marked this conversation as resolved.
Show resolved Hide resolved
)
);
}
4 changes: 2 additions & 2 deletions src/app/core/store/customer/basket/basket.effects.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import {
import { Basket } from 'ish-core/models/basket/basket.model';
import { BasketService } from 'ish-core/services/basket/basket.service';
import { RouterState } from 'ish-core/store/core/router/router.reducer';
import { loadUserByAPIToken, loginUser, loginUserSuccess } from 'ish-core/store/customer/user';
import { createUser, loadUserByAPIToken, loginUser, loginUserSuccess } from 'ish-core/store/customer/user';
import { ApiTokenService } from 'ish-core/utils/api-token/api-token.service';
import { mapErrorToAction, mapToPayloadProperty } from 'ish-core/utils/operators';

@@ -174,7 +174,7 @@ export class BasketEffects {
private anonymousBasket$ = createEffect(
() =>
combineLatest([this.store.pipe(select(getCurrentBasketId)), this.apiTokenService.apiToken$]).pipe(
sample(this.actions$.pipe(ofType(loginUser, loadUserByAPIToken))),
sample(this.actions$.pipe(ofType(loginUser, createUser, loadUserByAPIToken))),
startWith([undefined, undefined])
),
{ dispatch: false }
4 changes: 2 additions & 2 deletions src/app/core/store/customer/user/user.effects.spec.ts
Original file line number Diff line number Diff line change
@@ -243,11 +243,11 @@ describe('User Effects', () => {
});
});

it('should dispatch a CreateUserLogin action on successful user creation', () => {
it('should dispatch a LoginUserSuccess action on successful user creation', () => {
const credentials: Credentials = { login: '1234', password: 'xxx' };

const action = createUser({ credentials } as CustomerRegistrationType);
const completion = loginUser({ credentials });
const completion = loginUserSuccess({} as CustomerUserType);

actions$ = hot('-a', { a: action });
const expected$ = cold('-b', { b: completion });
6 changes: 1 addition & 5 deletions src/app/core/store/customer/user/user.effects.ts
Original file line number Diff line number Diff line change
@@ -121,11 +121,7 @@ export class UserEffects {
ofType(createUser),
mapToPayload(),
mergeMap((data: CustomerRegistrationType) =>
this.userService.createUser(data).pipe(
// TODO:see #IS-22750 - user should actually be logged in after registration
map(() => loginUser({ credentials: data.credentials })),
mapErrorToAction(createUserFail)
)
this.userService.createUser(data).pipe(map(loginUserSuccess), mapErrorToAction(createUserFail))
)
)
);