Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/shipping_easy/resources/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 27 additions & 5 deletions spec/resources/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -31,23 +31,45 @@
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
end

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