default to USD if there is no match

This commit is contained in:
Henry Oswald 2014-10-14 12:14:03 +01:00
parent 4a774981cf
commit 19a08f82a6
2 changed files with 8 additions and 1 deletions

View file

@ -39,6 +39,6 @@ module.exports = GeoIpLookup =
logger.err err:err, ip:ip, "problem getting currencyCode for ip, defaulting to USD"
return callback(null, "USD")
countryCode = ipDetails?.country_code?.toUpperCase()
currencyCode = currencyMappings[countryCode]
currencyCode = currencyMappings[countryCode] || "USD"
logger.log ip:ip, currencyCode:currencyCode, ipDetails:ipDetails, "got currencyCode for ip"
callback(err, currencyCode)

View file

@ -96,3 +96,10 @@ describe "GeoIpLookup", ->
@GeoIpLookup.getCurrencyCode @ipAddress, (err, currencyCode)->
currencyCode.should.equal "USD"
done()
it "should default to USD if there is no match for their country", (done)->
@stubbedResponse.country_code = "Non existant"
@GeoIpLookup.getDetails = sinon.stub().callsArgWith(1, null, @stubbedResponse)
@GeoIpLookup.getCurrencyCode @ipAddress, (err, currencyCode)->
currencyCode.should.equal "USD"
done()