Skip to content

Commit

Permalink
37560 - modified tests to include cart discount in createPayPalOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
LiudmylaMasliuk committed Dec 16, 2024
1 parent a8af3ae commit 737a224
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 12 additions & 0 deletions paypal-commercetools-extension/src/utils/map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const mapValidCommercetoolsLineItemsToPayPalItems = (

export const mapCommercetoolsCartToPayPalPriceBreakdown = ({
lineItems,
discountOnTotalPrice,
taxedShippingPrice,
}: Cart) => {
if (!lineItems || !lineItems[0]) {
Expand Down Expand Up @@ -237,6 +238,17 @@ export const mapCommercetoolsCartToPayPalPriceBreakdown = ({
type,
} as TypedMoney),
},
discount: discountOnTotalPrice
? {
currency_code: currencyCode,
value: mapCommercetoolsMoneyToPayPalMoney({
centAmount: discountOnTotalPrice.discountedAmount.centAmount ?? 0,
fractionDigits,
currencyCode,
type,
} as TypedMoney),
}
: undefined,
};
};

Expand Down
13 changes: 7 additions & 6 deletions paypal-commercetools-extension/tests/payment.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ const currencyData = {
const taxedPrice = {
totalNet: {
...currencyData,
centAmount: 16723,
centAmount: 16303,
},
totalGross: {
...currencyData,
centAmount: 19900,
centAmount: 19400,
},
totalTax: {
...currencyData,
centAmount: 3177,
centAmount: 3097,
},
};

const prices = {
totalPrice: {
...currencyData,
centAmount: 19900,
centAmount: 19400,
},
taxedPrice,
};
Expand All @@ -43,6 +43,7 @@ const mockConfigModule = () => {
locale: 'en',
lineItems: discountedLineItems,
...prices,
discountOnTotalPrice,
};
}),
}));
Expand All @@ -61,7 +62,7 @@ const mockConfigModule = () => {
mockConfigModule();

import { paymentController } from '../src/controllers/payments.controller';
import { discountedLineItems } from './constants';
import { discountedLineItems, discountOnTotalPrice } from './constants';

const amountPlanned = {
centAmount: 8200,
Expand Down Expand Up @@ -234,7 +235,7 @@ async function createValidTransaction(
}

const amountPlannedCentsWithTestResult: [number, string, string][] = [
[19900, 'same as cart', '199.00'],
[19400, 'same as cart', '194.00'],
[200000, 'more than in cart', '2000.00'],
[4200, 'less than in cart', '42.00'],
];
Expand Down

0 comments on commit 737a224

Please sign in to comment.