From 2e6c2c19262db6cce9e95aea364b4c553ed6a49f Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 13 Oct 2014 13:08:11 +0100 Subject: [PATCH] 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. --- .../web/app/coffee/infrastructure/GeoIpLookup.coffee | 2 ++ .../coffee/infrastructure/GeoIpLookupTests.coffee | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/services/web/app/coffee/infrastructure/GeoIpLookup.coffee b/services/web/app/coffee/infrastructure/GeoIpLookup.coffee index 19d1a202c5..a5a09b3249 100644 --- a/services/web/app/coffee/infrastructure/GeoIpLookup.coffee +++ b/services/web/app/coffee/infrastructure/GeoIpLookup.coffee @@ -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) \ No newline at end of file diff --git a/services/web/test/UnitTests/coffee/infrastructure/GeoIpLookupTests.coffee b/services/web/test/UnitTests/coffee/infrastructure/GeoIpLookupTests.coffee index ba5a53df35..d442ab6d7b 100644 --- a/services/web/test/UnitTests/coffee/infrastructure/GeoIpLookupTests.coffee +++ b/services/web/test/UnitTests/coffee/infrastructure/GeoIpLookupTests.coffee @@ -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()