Skip to content

Commit

Permalink
fix: if payment has failed after order creation navigate to checkout …
Browse files Browse the repository at this point in the history
…payment page and display a message (#184)
  • Loading branch information
SGrueber authored Apr 8, 2020
1 parent eb981ec commit 1a1bccb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/app/core/store/orders/orders.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,28 @@ describe('Orders Effects', () => {
});
});

describe('selectOrderAfterRedirectFailed', () => {
it('should navigate to /checkout/payment if order creation failed after redirect', fakeAsync(() => {
const action = new orderActions.SelectOrderAfterRedirectFail(undefined);
actions$ = of(action);

effects.selectOrderAfterRedirectFailed$.subscribe(noop, fail, noop);

tick(500);

expect(location.path()).toEqual('/checkout/payment?redirect=failure');
}));

it('should map to action of type LoadBasket', () => {
const action = new orderActions.SelectOrderAfterRedirectFail(undefined);
const completion = new LoadBasket();
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });

expect(effects.selectOrderAfterRedirectFailed$).toBeObservable(expected$);
});
});

describe('resetOrdersAfterLogout$', () => {
it('should map to action of type ResetOrders if LogoutUser action triggered', () => {
const action = new LogoutUser();
Expand Down
11 changes: 11 additions & 0 deletions src/app/core/store/orders/orders.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ export class OrdersEffects {
)
);

@Effect()
selectOrderAfterRedirectFailed$ = this.actions$.pipe(
ofType(ordersActions.OrdersActionTypes.SelectOrderAfterRedirectFail),
tap(() =>
this.router.navigate(['/checkout/payment'], {
queryParams: { redirect: 'failure' },
})
),
mapTo(new LoadBasket())
);

/**
* Trigger ResetOrders action after LogoutUser.
*/
Expand Down

0 comments on commit 1a1bccb

Please sign in to comment.