mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-28 03:21:56 +02: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:
@@ -30,5 +30,7 @@ module.exports = GeoIpLookup =
|
||||
|
||||
getCurrencyCode : (ip, callback)->
|
||||
GeoIpLookup.getDetails ip, (err, ipDetails)->
|
||||
if err? or !ipDetails?
|
||||
return callback(null, "USD")
|
||||
currencyCode = currencyMappings[ipDetails?.country_code?.toUpperCase()]
|
||||
callback(err, currencyCode)
|
||||
@@ -82,3 +82,15 @@ describe "GeoIpLookup", ->
|
||||
@GeoIpLookup.getCurrencyCode @ipAddress, (err, currencyCode)->
|
||||
currencyCode.should.equal "EUR"
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user