Skip to content

Commit

Permalink
feat(cart): only initially resolve cart if ID is in storage (#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Jun 29, 2023
1 parent bbd939e commit cc3db71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions libs/cart/state/src/effects/cart-resolver.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('@daffodil/cart/state | DaffCartResolverEffects', () => {
stubCart = cartFactory.create();
getCartIdSpy = spyOn(cartStorageService, 'getCartId');

getCartIdSpy.and.returnValue(String(stubCart.id));
getCartIdSpy.and.returnValue(stubCart.id);
cartResolverSpy.getCartOrFail.and.returnValue(of({
response: stubCart,
errors: [],
Expand All @@ -85,10 +85,24 @@ describe('@daffodil/cart/state | DaffCartResolverEffects', () => {
expect(effects).toBeTruthy();
});

it('should initiate cart resolution', () => {
expect(effects.ngrxOnInitEffects() instanceof DaffResolveCart).toEqual(
true,
);
describe('when there is a cart ID in storage', () => {
beforeEach(() => {
getCartIdSpy.and.returnValue(stubCart.id);
});

it('should initiate cart resolution', () => {
expect(effects.ngrxOnInitEffects() instanceof DaffResolveCart).toBeTrue();
});
});

describe('when there is a not cart ID in storage', () => {
beforeEach(() => {
getCartIdSpy.and.returnValue(null);
});

it('should not initiate cart resolution', () => {
expect(effects.ngrxOnInitEffects() instanceof DaffResolveCart).toBeFalse();
});
});

describe('onResolveCart() | when DaffResolveCartSuccess is dispatched', () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/cart/state/src/effects/cart-resolver.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ implements OnInitEffects {
) {}

ngrxOnInitEffects(): Action {
return new DaffResolveCart();
return this.cartStorage.getCartId() ? new DaffResolveCart() : { type: '' };
}

onResolveCart = createEffect(() => (): Observable<Action> => this.actions$.pipe(
Expand Down

0 comments on commit cc3db71

Please sign in to comment.