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:
Henry Oswald 2014-10-13 13:08:11 +01:00
parent e78e4d46b0
commit 2e6c2c1926
2 changed files with 14 additions and 0 deletions

View file

@ -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)

View file

@ -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()