Skip to content

Commit

Permalink
fix(cart): magento driver resolution fails for no discounts (#2638)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Dec 1, 2023
1 parent bd968f7 commit 1ea70a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libs/cart/driver/magento/src/models/responses/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface MagentoCart {
amount: MagentoMoney;
label: string;
}[];
discounts: {
discounts?: {
amount: MagentoMoney;
label: string;
}[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ describe('transformCartTotals', () => {
expect(transformedTotals[DaffCartTotalTypeEnum.tax].value).toEqual(0);
expect(transformedTotals[DaffCartTotalTypeEnum.shipping].value).toEqual(null);
});

describe('when discounts is null', () => {
beforeEach(() => {
stubMagentoCart.prices.discounts = null;
});

it('should set discount value to 0', () => {
const transformedTotals = transformCartTotals(stubMagentoCart).totals;

expect(transformedTotals[DaffCartTotalTypeEnum.discount].value).toEqual(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function transformCartTotals(cart: Partial<MagentoCart>): {totals: DaffCa
[DaffCartTotalTypeEnum.discount]: {
name: DaffCartTotalTypeEnum.discount,
label: 'Discounts',
value: daffAdd(...cart.prices.discounts.map((discount) => discount.amount.value)),
value: cart.prices.discounts ? daffAdd(...cart.prices.discounts.map((discount) => discount.amount.value)) : 0,
order: 6,
},
[DaffCartTotalTypeEnum.shipping]: {
Expand Down

0 comments on commit 1ea70a1

Please sign in to comment.