spec/zunnit_spec.rb in zunnit-0.3.8 vs spec/zunnit_spec.rb in zunnit-0.3.9
- old
+ new
@@ -77,10 +77,37 @@
pending "404"
response = Zunnit.api.get :recommendation_cluster_for_item,
:item_id => "20275919"
validate_response(response, :cluster)
end
+
+ it "should return recommendation product for item" do
+ intercept_request_to :get,
+ :action => :recommendation_products_for_item,
+ :params => { :item_id => "2121" },
+ :response => {
+ :status => 200,
+ :body => {
+ :msg => 'Ok',
+ :status => 200,
+ :rec_id => "dba158a81706dbd",
+ :products => [
+ {
+ :id => "MLB199848107",
+ :title => "ReloĢgio Nike",
+ :price => 199.99,
+ :thumbnail => "http://img1.mlstatic.com/s_MLB_v_I_f_156827423_9293.jpg"
+ }
+ ]
+ }.to_json
+ }
+
+ response = Zunnit.api.get :recommendation_products_for_item,
+ :item_id => "2121"
+
+ validate_response(response, :products)
+ end
end
describe "post" do
it "should return status 200 when add an item" do
intercept_request_to :post,
@@ -125,12 +152,13 @@
end
def intercept_request_to(method, options)
action = options.delete(:action)
params = options.delete(:params)
+ params = params.merge :api_key => Zunnit.key
response = options.delete(:response)
uri = URI.parse(Zunnit.url).merge(Zunnit.actions[action])
- uri = uri + params.map {|k,v| "#{k}=#{v}" }.join("&") unless method.to_s =~ /post|put/
+ uri.query = params.map {|k,v| "#{k}=#{v}" }.join("&") unless method.to_s =~ /post|put/
FakeWeb.register_uri(method, uri, response)
end
end