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

default to USD if there is no match

Henry Oswald 12 лет назад
Родитель
Сommit
19a08f82a6

+ 1 - 1
services/web/app/coffee/infrastructure/GeoIpLookup.coffee

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

+ 7 - 0
services/web/test/UnitTests/coffee/infrastructure/GeoIpLookupTests.coffee

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