Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-164094 Fix algorithm for calculation of PUF optical #3370

Open
wants to merge 3 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libs/deps/mas/commerce.js

Large diffs are not rendered by default.

142 changes: 71 additions & 71 deletions libs/deps/mas/mas.js

Large diffs are not rendered by default.

142 changes: 71 additions & 71 deletions libs/features/mas/dist/mas.js

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions libs/features/mas/src/price/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ const opticalPriceDivisors = {
[Term.TWO_YEARS]: 24,
};

/**
* Special per-currency handling rules for optical prices.
* @type { { [currencyCode: string]: (opticalPrice: number) => number } }
*/
const opticalPriceCurrencyRules = {
CHF: (opticalPrice) => Math.round(opticalPrice * 20) / 20,
};

/**
* Creates and returns a rule for rounding optical prices based on price characteristics.
* @param { ({ price: number, divisor: number, usePrecision: boolean }) => boolean } accept
bozojovicic marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -59,8 +51,7 @@ const opticalPriceRoundingRules = [
opticalPriceRoundingRule(
// round optical price up to 2 decimals
({ usePrecision }) => usePrecision,
({ divisor, price }) =>
Math.ceil(Math.floor((price * 10000) / divisor) / 100) / 100
({ divisor, price }) => Math.round((price / divisor) * 100.0) / 100.0
),
opticalPriceRoundingRule(
// round optical price up to integer
Expand Down Expand Up @@ -235,7 +226,7 @@ const formatOpticalPrice = (data) => {
divisor > 1
? RecurrenceTerm.MONTH
: recurrenceTerms[commitment]?.[term],
(price, { currencySymbol }) => {
(price) => {
const priceData = {
divisor,
price,
Expand All @@ -248,9 +239,7 @@ const formatOpticalPrice = (data) => {
throw new Error(
`Missing rounding rule for: ${JSON.stringify(priceData)}`
);
const adapt =
opticalPriceCurrencyRules[currencySymbol] ?? ((value) => value);
return adapt(round(priceData));
return round(priceData);
}
);
};
Expand Down

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions libs/features/mas/test/price/utilities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ const OPTICAL_TEST_CASES = [
usePrecision: true,
},
[
[23.7, 'CHF2.00'],
[24.991, 'CHF2.10'],
[24.77, 'CHF2.05'],
[24.8899, 'CHF2.10'],
[12000.24321, 'CHF1000.05'],
[12000.489, 'CHF1000.05'],
[23.7, 'CHF1.98'],
[24.991, 'CHF2.08'],
[24.77, 'CHF2.06'],
[24.8899, 'CHF2.07'],
[12000.24321, 'CHF1000.02'],
[12000.489, 'CHF1000.04'],
],
],
[
Expand All @@ -48,9 +48,9 @@ const OPTICAL_TEST_CASES = [
},
[
[23.7, 'EUR1.98'],
[24.99, 'EUR2.09'],
[24.77, 'EUR2.07'],
[24.88, 'EUR2.08'],
[24.99, 'EUR2.08'],
[24.77, 'EUR2.06'],
[24.88, 'EUR2.07'],
[12000.24, 'EUR1000.02'],
[12000.48, 'EUR1000.04'],
],
Expand All @@ -64,9 +64,9 @@ const OPTICAL_TEST_CASES = [
},
[
[23.7, 'US$1.98'],
[24.99, 'US$2.09'],
[24.77, 'US$2.07'],
[24.88, 'US$2.08'],
[24.99, 'US$2.08'],
[24.77, 'US$2.06'],
[24.88, 'US$2.07'],
[820.2, 'US$68.35'],
[12000.24, 'US$1000.02'],
[12000.48, 'US$1000.04'],
Expand All @@ -81,11 +81,11 @@ const OPTICAL_TEST_CASES = [
},
[
[23.7, 'CHF 23.70'],
[24.99, 'CHF 25.00'],
[24.77, 'CHF 24.75'],
[24.88, 'CHF 24.90'],
[1200.24, 'CHF 1,200.25'],
[1200.48, 'CHF 1,200.50'],
[24.99, 'CHF 24.99'],
[24.77, 'CHF 24.77'],
[24.88, 'CHF 24.88'],
[1200.24, 'CHF 1,200.24'],
[1200.48, 'CHF 1,200.48'],
],
],
[
Expand Down Expand Up @@ -190,7 +190,7 @@ const OPTICAL_TEST_CASES = [
usePrecision: true,
isIndianPrice: true,
},
[[40600000, '₹33,83,333.34']],
[[40600000, '₹33,83,333.33']],
],
];

Expand Down
Loading