Commit d01a8139 by jaebradley Committed by Jae Bradley

parse price and update multiplication

parent a9367db8
...@@ -257,11 +257,14 @@ define([ ...@@ -257,11 +257,14 @@ define([
}, },
formatToLocalPrice: function(prefix, priceInUsd) { formatToLocalPrice: function(prefix, priceInUsd) {
var countryData = Cookies.getJSON('edx-price-l10n'); var countryData = Cookies.getJSON('edx-price-l10n'),
parsedPriceInUsd;
// Default to USD when the exchange rate cookie doesn't exist // Default to USD when the exchange rate cookie doesn't exist
if (BasketPage.isValidLocalCurrencyCookie(countryData) && countryData.countryCode !== 'USA') { if (BasketPage.isValidLocalCurrencyCookie(countryData) && countryData.countryCode !== 'USA') {
return countryData.symbol + Math.round(priceInUsd * countryData.rate).toLocaleString() + ' ' // assumes all formatted prices have a comma every three places
parsedPriceInUsd = parseFloat(priceInUsd.replace(',', ''));
return countryData.symbol + Math.round(parsedPriceInUsd * countryData.rate).toLocaleString() + ' '
+ countryData.code + ' *'; + countryData.code + ' *';
} else { } else {
return prefix + priceInUsd; return prefix + priceInUsd;
......
...@@ -587,9 +587,9 @@ define([ ...@@ -587,9 +587,9 @@ define([
describe('formatToLocalPrice', function() { describe('formatToLocalPrice', function() {
var EDX_PRICE_LOCATION_COOKIE_NAME = 'edx-price-l10n', var EDX_PRICE_LOCATION_COOKIE_NAME = 'edx-price-l10n',
USD_VALUE = 100.25, USD_VALUE = '1,234.56',
ANOTHER_USD_VALUE = '123.45',
PREFIX = 'PREFIX', PREFIX = 'PREFIX',
EXPECTED_USD_PRICE = '100.25',
COOKIE_VALUES = {countryCode: 'FOO', rate: 2, code: 'BAR', symbol: 'BAZ'}; COOKIE_VALUES = {countryCode: 'FOO', rate: 2, code: 'BAR', symbol: 'BAZ'};
beforeEach(function() { beforeEach(function() {
...@@ -601,17 +601,27 @@ define([ ...@@ -601,17 +601,27 @@ define([
}); });
it('should return prefixed price when cookie does not exist', function() { it('should return prefixed price when cookie does not exist', function() {
expect(BasketPage.formatToLocalPrice(PREFIX, USD_VALUE)).toEqual(PREFIX + EXPECTED_USD_PRICE); expect(BasketPage.formatToLocalPrice(PREFIX, USD_VALUE)).toEqual(PREFIX + USD_VALUE);
}); });
it('should return prefixed price when country code is USA', function() { it('should return prefixed price when country code is USA', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, {countryCode: 'USA'}); Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, {countryCode: 'USA'});
expect(BasketPage.formatToLocalPrice(PREFIX, USD_VALUE)).toEqual(PREFIX + EXPECTED_USD_PRICE); expect(BasketPage.formatToLocalPrice(PREFIX, USD_VALUE)).toEqual(PREFIX + USD_VALUE);
});
it('should return prefixed price when country code is USA', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, {countryCode: 'USA'});
expect(BasketPage.formatToLocalPrice(PREFIX, USD_VALUE)).toEqual(PREFIX + USD_VALUE);
}); });
it('should return formatted local price value when non-US cookie exists', function() { it('should return formatted local price value when non-US cookie exists', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, COOKIE_VALUES); Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, COOKIE_VALUES);
expect(BasketPage.formatToLocalPrice(PREFIX, USD_VALUE)).toEqual('BAZ201 BAR *'); expect(BasketPage.formatToLocalPrice(PREFIX, USD_VALUE)).toEqual('BAZ2,469 BAR *');
});
it('should return non-comma separated local price value when non-US cookie exists', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, COOKIE_VALUES);
expect(BasketPage.formatToLocalPrice(PREFIX, ANOTHER_USD_VALUE)).toEqual('BAZ247 BAR *');
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment