🐛 Fixed incorrect price shown for offer page with fixed discount

no refs

the fixed discount is only applied to offer if the offer currency matches with original price currency. The bug happened due to case difference between the offer and price currencies which should be compared case insensitive
This commit is contained in:
Rishabh 2021-11-22 18:19:00 +05:30
parent 3ad4e9c4c9
commit f4fdda94e5
3 changed files with 24 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import AppContext from '../../AppContext';
import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg';
import CloseButton from '../common/CloseButton';
import InputForm from '../common/InputForm';
import {getCurrencySymbol, getProductFromId, hasMultipleProductsFeature} from '../../utils/helpers';
import {getCurrencySymbol, getProductFromId, hasMultipleProductsFeature, isSameCurrency} from '../../utils/helpers';
import {ValidateInputForm} from '../../utils/form';
const React = require('react');
@ -445,7 +445,7 @@ export default class OfferPage extends React.Component {
const price = offer.cadence === 'month' ? product.monthlyPrice : product.yearlyPrice;
const originalAmount = price.amount;
let updatedAmount;
if (offer.type === 'fixed' && offer.currency === price.currency) {
if (offer.type === 'fixed' && isSameCurrency(offer.currency, price.currency)) {
updatedAmount = ((originalAmount - offer.amount)) / 100;
return updatedAmount > 0 ? updatedAmount : 0;
} else if (offer.type === 'percent') {

View File

@ -484,6 +484,10 @@ export const createPopupNotification = ({type, status, autoHide, duration, close
};
};
export function isSameCurrency(currency1, currency2) {
return currency1?.toLowerCase() === currency2?.toLowerCase();
}
export function getPriceIdFromPageQuery({site, pageQuery}) {
const productMonthlyPriceQueryRegex = /^(?:(\S+?))?\/monthly$/;
const productYearlyPriceQueryRegex = /^(?:(\S+?))?\/yearly$/;

View File

@ -1,4 +1,4 @@
import {getPriceIdFromPageQuery} from './helpers';
import {getPriceIdFromPageQuery, isSameCurrency} from './helpers';
import * as Fixtures from './fixtures';
describe('Helpers - ', () => {
@ -11,4 +11,21 @@ describe('Helpers - ', () => {
const value = mockPriceIdFn({site: siteData, pageQuery});
expect(value).toBe(expectedPriceId);
});
describe('isSameCurrency - ', () => {
test('can match two currencies correctly ', () => {
let currency1 = 'USD';
let currency2 = 'USD';
expect(isSameCurrency(currency1, currency2)).toBe(true);
});
test('can match currencies with case mismatch', () => {
let currency1 = 'USD';
let currency2 = 'usd';
expect(isSameCurrency(currency1, currency2)).toBe(true);
});
test('can match currencies with case mismatch', () => {
let currency1 = 'eur';
let currency2 = 'usd';
expect(isSameCurrency(currency1, currency2)).toBe(false);
});
});
});