Skip to content

Commit

Permalink
fix(cart): selectIsBillingSameAsShipping does not respect IDs (#2543)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Aug 11, 2023
1 parent 167bb4a commit bc63ae8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions libs/cart/state/src/selectors/cart/cart.selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,25 @@ describe('Cart | Selector | Cart', () => {
});
});

describe('and the shipping and billing address are the same except for ID', () => {
beforeEach(() => {
store.dispatch(new DaffCartLoadSuccess({
...cart,
shipping_address: {
...cart.billing_address,
id: `not ${cart.billing_address.id}`,
},
}));
});

it('should return false', () => {
const selector = store.pipe(select(selectIsBillingSameAsShipping));
const expected = cold('a', { a: false });

expect(selector).toBeObservable(expected);
});
});

describe('and the shipping and billing address are not the same', () => {
beforeEach(() => {
store.dispatch(new DaffCartLoadSuccess({
Expand Down
5 changes: 4 additions & 1 deletion libs/cart/state/src/selectors/cart/cart.selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,10 @@ const createCartSelectors = <
const selectIsBillingSameAsShipping = createSelector(
selectCartShippingAddress,
selectCartBillingAddress,
(shippingAddress, billingAddress) => daffComparePersonalAddresses(shippingAddress, billingAddress),
(shippingAddress, billingAddress) =>
shippingAddress?.id || billingAddress?.id
? shippingAddress?.id === billingAddress?.id
: daffComparePersonalAddresses(shippingAddress, billingAddress),
);

const selectHasBillingAddress = createSelector(
Expand Down

0 comments on commit bc63ae8

Please sign in to comment.