Skip to content

Commit 6f52623

Browse files
Maxscoresleesharma
authored andcommitted
Fix Amazon search with spaces (#192)
* Add Spec to search items with spaces * Add search with spaces xml response * Add webmock config for search with spaces * Update amazon_item_search_endpoint to convert spaces to underscore in request * Update webmock return an error query request to use underscores * Update xml response * Fix robocop comments
1 parent 23ddba6 commit 6f52623

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.4.1

lib/amazon_product_api/item_search_endpoint.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def params
8484
'Operation' => 'ItemSearch',
8585
'ResponseGroup' => 'ItemAttributes,Offers,Images',
8686
'SearchIndex' => 'All',
87-
'Keywords' => query.to_s,
87+
'Keywords' => query.to_s.tr(' ', '_'),
8888
'ItemPage' => page.to_s
8989
}
9090

spec/features/managing_items_and_wishlists_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
expect(page).to have_text 'Needed: 18'
3636
end
3737

38+
scenario 'I can search for items with spaces', :external do
39+
visit wishlist_path(wishlist)
40+
click_link 'Add to Wishlist'
41+
fill_in 'search_field', with: 'corgi pillow'
42+
click_button 'Search Amazon'
43+
44+
expect(page).to_not have_text 'Could not connect to Amazon.'
45+
end
46+
3847
scenario 'I get redirected to the search page when Amazon returns an error code.', :external do
3948
visit wishlist_path(wishlist)
4049
click_link 'Add to Wishlist'

spec/fixtures/files/amazon_corgi_pillow_search_response.xml

+1
Large diffs are not rendered by default.

spec/support/webmock.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
'Keywords' => 'corgi'))
1414
.to_return(body: search_response)
1515

16+
# Item Search with Spaces
17+
search_response = file_fixture('amazon_corgi_pillow_search_response.xml').read
18+
stub_request(:get, 'webservices.amazon.com/onca/xml')
19+
.with(query: hash_including('Operation' => 'ItemSearch',
20+
'Keywords' => 'corgi_pillow'))
21+
.to_return(body: search_response)
22+
1623
# Item Lookup
1724
lookup_response = file_fixture('amazon_corgi_lookup_response.xml').read
1825
stub_request(:get, 'webservices.amazon.com/onca/xml')
@@ -21,7 +28,7 @@
2128
.to_return(body: lookup_response)
2229

2330
stub_request(:get, 'webservices.amazon.com/onca/xml')
24-
.with(query: hash_including('Keywords' => 'return an error'))
31+
.with(query: hash_including('Keywords' => 'return_an_error'))
2532
.to_return(status: 500)
2633
end
2734
end

0 commit comments

Comments
 (0)