mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
default to USD in geo ip lookup.
Decided to put default logic in the GeoIpLookup.getCurrencyCode as we are going to want this default everywhere we use it.
This commit is contained in:
parent
e78e4d46b0
commit
2e6c2c1926
2 changed files with 14 additions and 0 deletions
|
@ -30,5 +30,7 @@ module.exports = GeoIpLookup =
|
||||||
|
|
||||||
getCurrencyCode : (ip, callback)->
|
getCurrencyCode : (ip, callback)->
|
||||||
GeoIpLookup.getDetails ip, (err, ipDetails)->
|
GeoIpLookup.getDetails ip, (err, ipDetails)->
|
||||||
|
if err? or !ipDetails?
|
||||||
|
return callback(null, "USD")
|
||||||
currencyCode = currencyMappings[ipDetails?.country_code?.toUpperCase()]
|
currencyCode = currencyMappings[ipDetails?.country_code?.toUpperCase()]
|
||||||
callback(err, currencyCode)
|
callback(err, currencyCode)
|
|
@ -82,3 +82,15 @@ describe "GeoIpLookup", ->
|
||||||
@GeoIpLookup.getCurrencyCode @ipAddress, (err, currencyCode)->
|
@GeoIpLookup.getCurrencyCode @ipAddress, (err, currencyCode)->
|
||||||
currencyCode.should.equal "EUR"
|
currencyCode.should.equal "EUR"
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should default to USD if there is an error", (done)->
|
||||||
|
@GeoIpLookup.getDetails = sinon.stub().callsArgWith(1, "problem")
|
||||||
|
@GeoIpLookup.getCurrencyCode @ipAddress, (err, currencyCode)->
|
||||||
|
currencyCode.should.equal "USD"
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should default to USD if there are no details", (done)->
|
||||||
|
@GeoIpLookup.getDetails = sinon.stub().callsArgWith(1)
|
||||||
|
@GeoIpLookup.getCurrencyCode @ipAddress, (err, currencyCode)->
|
||||||
|
currencyCode.should.equal "USD"
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in a new issue