Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
235656af
Commit
235656af
authored
Oct 23, 2017
by
jaebradley
Committed by
Jae Bradley
Oct 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add currency cookie validation
delete code
parent
80f51474
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
3 deletions
+45
-3
ecommerce/static/js/pages/basket_page.js
+6
-2
ecommerce/static/js/test/specs/pages/basket_page_spec.js
+39
-1
No files found.
ecommerce/static/js/pages/basket_page.js
View file @
235656af
...
...
@@ -236,10 +236,14 @@ define([
});
},
isValidLocalCurrencyCookie
:
function
(
cookie
)
{
return
!!
cookie
&&
!!
cookie
.
countryCode
&&
!!
cookie
.
symbol
&&
!!
cookie
.
rate
&&
!!
cookie
.
code
;
},
addPriceDisclaimer
:
function
()
{
var
price
=
$
(
'#basket-total'
).
find
(
'> .price'
).
text
(),
countryData
=
Cookies
.
getJSON
(
'edx-price-l10n'
);
if
(
countryData
&&
countryData
.
countryCode
!==
'USA'
)
{
if
(
BasketPage
.
isValidLocalCurrencyCookie
(
countryData
)
&&
countryData
.
countryCode
!==
'USA'
)
{
$
(
'<span>'
).
attr
(
'class'
,
'price-disclaimer'
)
.
text
(
'* This total contains an approximate conversion. You will be charged '
+
price
+
' USD.'
)
.
appendTo
(
'div[aria-labelledby="order-details-region"]'
);
...
...
@@ -250,7 +254,7 @@ define([
var
countryData
=
Cookies
.
getJSON
(
'edx-price-l10n'
);
// Default to USD when the exchange rate cookie doesn't exist
if
(
countryData
&&
countryData
.
countryCode
!==
'USA'
)
{
if
(
BasketPage
.
isValidLocalCurrencyCookie
(
countryData
)
&&
countryData
.
countryCode
!==
'USA'
)
{
return
countryData
.
symbol
+
Math
.
round
(
priceInUsd
*
countryData
.
rate
)
+
' '
+
countryData
.
code
+
' *'
;
}
else
{
...
...
ecommerce/static/js/test/specs/pages/basket_page_spec.js
View file @
235656af
...
...
@@ -733,7 +733,8 @@ define([
Cookies
.
remove
(
EDX_PRICE_LOCATION_COOKIE_NAME
);
});
it
(
'should not add disclaimer when cookie does not exist'
,
function
()
{
it
(
'should not add disclaimer when cookie is Invalid'
,
function
()
{
spyOn
(
BasketPage
,
'isValidLocalCurrencyCookie'
).
and
.
returnValue
(
false
);
BasketPage
.
addPriceDisclaimer
();
expect
(
0
).
toEqual
(
$
(
'.price-disclaimer'
).
length
);
});
...
...
@@ -753,6 +754,43 @@ define([
.
toEqual
(
$
(
'.price-disclaimer'
).
text
());
});
});
describe
(
'isValidLocalCurrencyCookie'
,
function
()
{
var
COOKIE_VALUES
=
{
countryCode
:
'FOO'
,
rate
:
2
,
code
:
'BAR'
,
symbol
:
'BAZ'
};
it
(
'should be invalid if undefined'
,
function
()
{
expect
(
BasketPage
.
isValidLocalCurrencyCookie
(
undefined
)).
toBe
(
false
);
});
it
(
'should be invalid if no country code exists'
,
function
()
{
var
cookie
=
_
.
clone
(
COOKIE_VALUES
);
delete
cookie
.
countryCode
;
expect
(
BasketPage
.
isValidLocalCurrencyCookie
(
cookie
)).
toBe
(
false
);
});
it
(
'should be invalid if no symbol exists'
,
function
()
{
var
cookie
=
_
.
clone
(
COOKIE_VALUES
);
delete
cookie
.
symbol
;
expect
(
BasketPage
.
isValidLocalCurrencyCookie
(
cookie
)).
toBe
(
false
);
});
it
(
'should be invalid if no rate exists'
,
function
()
{
var
cookie
=
_
.
clone
(
COOKIE_VALUES
);
delete
cookie
.
rate
;
expect
(
BasketPage
.
isValidLocalCurrencyCookie
(
cookie
)).
toBe
(
false
);
});
it
(
'should be invalid if no code exists'
,
function
()
{
var
cookie
=
_
.
clone
(
COOKIE_VALUES
);
delete
cookie
.
code
;
expect
(
BasketPage
.
isValidLocalCurrencyCookie
(
cookie
)).
toBe
(
false
);
});
it
(
'should be valid if cookie exists and all necessary fields exist'
,
function
()
{
var
cookie
=
_
.
clone
(
COOKIE_VALUES
);
expect
(
BasketPage
.
isValidLocalCurrencyCookie
(
cookie
)).
toBe
(
true
);
});
});
});
}
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment