Просмотр исходного кода

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.
Henry Oswald 12 лет назад
Родитель
Сommit
2e6c2c1926

+ 2 - 0
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)

+ 12 - 0
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()