From e6f4d46a243a562a636f6a247e157253b49b9314 Mon Sep 17 00:00:00 2001 From: James Zetlen Date: Fri, 19 Oct 2018 14:26:12 -0500 Subject: [PATCH] fix(venia): rm staleGuestCartId on error (#354) * fix(venia): rm staleGuestCartId on error Fixes #344. * fix: misspelling in doc * fix: simplify omit logic --- .../src/reducers/__tests__/cart.spec.js | 18 +++++++++--------- packages/venia-concept/src/reducers/cart.js | 5 ++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/venia-concept/src/reducers/__tests__/cart.spec.js b/packages/venia-concept/src/reducers/__tests__/cart.spec.js index a238e7a24e..5b67e7a235 100644 --- a/packages/venia-concept/src/reducers/__tests__/cart.spec.js +++ b/packages/venia-concept/src/reducers/__tests__/cart.spec.js @@ -66,15 +66,15 @@ test('getDetails.receive: merges payload with state', () => { }); }); -test('getDetails.receive: returns same state on error, letting the app slice handle error display', () => { - const state = { other: 'stuff', totals: { total: 100 } }; - expect( - cartReducers(state, { - type: actions.getDetails.receive, - payload: new Error('That did not work at all'), - error: true - }) - ).toEqual(state); +test('getDetails.receive: removes guestCartId on error', () => { + const state = { guestCartId: 123, other: 'stuff', totals: { total: 100 } }; + const nextState = cartReducers(state, { + type: actions.getDetails.receive, + payload: new Error('That did not work at all'), + error: true + }); + expect(nextState).toMatchObject({ other: 'stuff', totals: { total: 100 } }); + expect(nextState.guestCartId).not.toBeTruthy(); }); test('checkoutActions.order.accept: cart resets to initial state', () => { diff --git a/packages/venia-concept/src/reducers/cart.js b/packages/venia-concept/src/reducers/cart.js index 18a0644277..14a8ea46ca 100644 --- a/packages/venia-concept/src/reducers/cart.js +++ b/packages/venia-concept/src/reducers/cart.js @@ -24,7 +24,10 @@ const reducerMap = { }, [actions.getDetails.receive]: (state, { payload, error }) => { if (error) { - return state; + return { + ...state, + guestCartId: null + }; } return {