From c62cf67eb79d367c9221a1fbed070f98b3463360 Mon Sep 17 00:00:00 2001 From: Theo Mills Date: Wed, 14 Oct 2015 15:31:10 -0500 Subject: [PATCH] Add update status and recipient calls. --- lib/shipping_easy/resources/order.rb | 8 +++++++ spec/resources/order_spec.rb | 32 +++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/shipping_easy/resources/order.rb b/lib/shipping_easy/resources/order.rb index e37e5c6..72e0211 100644 --- a/lib/shipping_easy/resources/order.rb +++ b/lib/shipping_easy/resources/order.rb @@ -18,4 +18,12 @@ class ShippingEasy::Resources::Order < ShippingEasy::Resources::Base "/orders" end end + + command :update_status, http_method: :put do |args| + "/stores/#{args.delete(:store_api_key)}/orders/#{args.delete(:id)}/status" + end + + command :update_recipient, http_method: :put do |args| + "/stores/#{args.delete(:store_api_key)}/orders/#{args.delete(:id)}/recipient" + end end diff --git a/spec/resources/order_spec.rb b/spec/resources/order_spec.rb index 1cb8907..824d0ce 100644 --- a/spec/resources/order_spec.rb +++ b/spec/resources/order_spec.rb @@ -5,7 +5,7 @@ describe ".find_all" do context "when store ID is not included" do it "sends a request with the expected options" do - ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/orders", + expect(ShippingEasy::Resources::Order).to receive(:execute_request!).with({ :relative_path => "/orders", :http_method => :get, :params => { :page => 2, :per_page => 3, @@ -17,7 +17,7 @@ context "when store ID is included" do it "sends a request with the expected options" do - ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/stores/123456/orders", + expect(ShippingEasy::Resources::Order).to receive(:execute_request!).with({ :relative_path => "/stores/123456/orders", :http_method => :get, :params => { :page => 2, :per_page => 3, @@ -31,14 +31,14 @@ describe ".find" do context "when store ID is not included" do it "sends a request with the expected options" do - ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/orders/2", :http_method => :get }, :public) + expect(ShippingEasy::Resources::Order).to receive(:execute_request!).with({ :relative_path => "/orders/2", :http_method => :get }, :public) ShippingEasy::Resources::Order.find(:id => 2) end end context "when store ID is included" do it "sends a request with the expected options" do - ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/stores/123456/orders/2", :http_method => :get }, :public) + expect(ShippingEasy::Resources::Order).to receive(:execute_request!).with({ :relative_path => "/stores/123456/orders/2", :http_method => :get }, :public) ShippingEasy::Resources::Order.find(:store_api_key => "123456", :id => 2) end end @@ -46,8 +46,30 @@ describe ".create" do it "sends a request with the expected options" do - ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/stores/123456/orders", :http_method => :post, payload: { name: "Jack" } }, :public) + expect(ShippingEasy::Resources::Order).to receive(:execute_request!).with({ :relative_path => "/stores/123456/orders", :http_method => :post, payload: { name: "Jack" } }, :public) ShippingEasy::Resources::Order.create(:store_api_key => "123456", payload: { name: "Jack" }) end end + + describe ".update_recipient" do + let(:payload) do + { recipient: { first_name: "Jack" } } + end + + it "sends a request with the expected options" do + expect(ShippingEasy::Resources::Order).to receive(:execute_request!).with({ :relative_path => "/stores/123456/orders/2/recipient", :http_method => :put, payload: payload}, :public) + ShippingEasy::Resources::Order.update_recipient(:store_api_key => "123456", id: 2, payload: payload) + end + end + + describe ".change_status" do + let(:payload) do + { order: { status: "shipped" } } + end + + it "sends a request with the expected options" do + expect(ShippingEasy::Resources::Order).to receive(:execute_request!).with({ :relative_path => "/stores/123456/orders/2/status", :http_method => :put, payload: payload}, :public) + ShippingEasy::Resources::Order.update_status(:store_api_key => "123456", id: 2, payload: payload) + end + end end