Permalink
Browse files

Ensure we ignore blank address entries

  • Loading branch information...
1 parent 130e744 commit 455597bdf1f2cdd61fe29c915f4317ea95ea4c33 @csaunders csaunders committed May 16, 2012
Showing with 27 additions and 4 deletions.
  1. +8 −2 lib/active_fulfillment/fulfillment/services/amazon_mws.rb
  2. +19 −2 test/unit/services/amazon_mws_test.rb
View
10 lib/active_fulfillment/fulfillment/services/amazon_mws.rb
@@ -56,7 +56,8 @@ class AmazonMarketplaceWebService < Service
:city => "DestinationAddress.City",
:state => "DestinationAddress.StateOrProvinceCode",
:country => "DestinationAddress.CountryCode",
- :zip => "DestinationAddress.PostalCode"
+ :zip => "DestinationAddress.PostalCode",
+ :phone => "DestinationAddress.PhoneNumber"
},
:line_items => {
:comment => "Items.member.%d.DisplayableComment",
@@ -400,8 +401,13 @@ def build_tracking_request(order_id, options)
def build_address(address)
requires!(address, :name, :address1, :city, :state, :country, :zip)
ary = address.map{ |key, value|
- [escape(LOOKUPS[:destination_address][key]), escape(value)]
+ if value.length > 0
+ [escape(LOOKUPS[:destination_address][key]), escape(value)]
+ else
+ nil
+ end
}
+ ary.reject(&:nil?)
Hash[ary]
end
View
21 test/unit/services/amazon_mws_test.rb
@@ -20,7 +20,8 @@ def setup
:city => 'Beverly Hills',
:state => 'CA',
:country => 'US',
- :zip => '90210'
+ :zip => '90210',
+ :phone => "(555)555-5555"
}
@line_items = [
@@ -103,11 +104,27 @@ def test_build_address
"DestinationAddress.City" => @address[:city].gsub(' ', '%20'),
"DestinationAddress.StateOrProvinceCode" => @address[:state].gsub(' ', '%20'),
"DestinationAddress.CountryCode" => @address[:country].gsub(' ', '%20'),
- "DestinationAddress.PostalCode" => @address[:zip].gsub(' ', '%20')
+ "DestinationAddress.PostalCode" => @address[:zip].gsub(' ', '%20'),
+ "DestinationAddress.PhoneNumber" => CGI.escape(@address[:phone])
}
assert_equal expected_items, @service.build_address(@address)
end
+ def test_build_address_with_missing_fields
+ expected_items = {
+ "DestinationAddress.Name" => @address[:name].gsub(' ', '%20'),
+ "DestinationAddress.Line1" => @address[:address1].gsub(' ', '%20'),
+ "DestinationAddress.City" => @address[:city].gsub(' ', '%20'),
+ "DestinationAddress.StateOrProvinceCode" => @address[:state].gsub(' ', '%20'),
+ "DestinationAddress.CountryCode" => @address[:country].gsub(' ', '%20'),
+ "DestinationAddress.PostalCode" => @address[:zip].gsub(' ', '%20'),
+ "DestinationAddress.PhoneNumber" => CGI.escape(@address[:phone])
+ }
+ @address[:address2] = ""
+
+ assert_equal expected_items, @service.build_address(@address)
+ end
+
def test_integrated_registration_url_creation
service = AmazonMarketplaceWebService.new(:login => "AKIAFJPPO5KLY6G4XO7Q", :password => "aaa", :app_id => "1014f5ad-c359-4e86-8e50-bb8f8e431a9")
options = {

0 comments on commit 455597b

Please sign in to comment.