Skip to content

Commit

Permalink
Add index call for shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorothee Laugwitz authored and Dorothee committed Jan 8, 2016
1 parent 3162e10 commit 32e2fac
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/shipcloud/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module Shipcloud
class Shipment < Base
include Shipcloud::Operations::Delete
include Shipcloud::Operations::Update
include Shipcloud::Operations::All

attr_accessor :from, :to, :carrier, :package, :reference_number
attr_reader :id, :created_at, :carrier_tracking_no, :tracking_url, :label_url, :packages, :price
end
end
end
105 changes: 105 additions & 0 deletions spec/shipcloud/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,109 @@
Shipcloud::Shipment.delete("123")
end
end

describe ".all" do
it "makes a new Get request using the correct API endpoint" do
expect(Shipcloud).to receive(:request).with(:get, "shipments", {}).and_return([])
Shipcloud::Shipment.all
end

it "returns a list of Shipment objects" do
stub_shipments_request

shipments = Shipcloud::Shipment.all

shipments.each do |shipment|
expect(shipment).to be_a Shipcloud::Shipment
end
end

it "initializes the Shipment objects correctly" do
stub_shipments_request
allow(Shipcloud::Shipment).to receive(:new)

Shipcloud::Shipment.all

expect(Shipcloud::Shipment).to have_received(:new).with(hermes_shipment)
expect(Shipcloud::Shipment).to have_received(:new).with(ups_shipment)
end
end

def stub_shipments_request
allow(Shipcloud).to receive(:request).
with(:get, "shipments", {}).
and_return([hermes_shipment, ups_shipment])
end

def hermes_shipment
{ "id" => "86afb143f9c9c0cfd4eb7a7c26a5c616585a6271",
"carrier_tracking_no" => "43128000105",
"carrier" => "hermes",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.5,
"tracking_url" => "http://track.shipcloud.dev/de/86afb143f9",
"to" => {
"first_name" => "Hans",
"last_name" => "Meier",
"street" => "Semmelweg",
"street_no" => "1",
"zip_code" => "12345",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "be81573799958587ae891b983aabf9c4089fc462",
"length" => 10.0,
"width" => 10.0,
"height" => 10.0,
"weight" => 1.5
}
}
end

def ups_shipment
{ "id" => "be81573799958587ae891b983aabf9c4089fc462",
"carrier_tracking_no" => "1Z12345E1305277940",
"carrier" => "ups",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.0,
"tracking_url" => "http://track.shipcloud.dev/de/be598a2fd2",
"to" => {
"first_name" => "Test",
"last_name" => "Kunde",
"street" => "Gluckstr.",
"street_no" => "57",
"zip_code" => "22081",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "74d4f1fc193d8a7ca542d1ee4e2021f3ddb82242",
"length" => 15.0,
"width" => 20.0,
"height" => 10.0,
"weight" => 2.0
}
}
end
end

0 comments on commit 32e2fac

Please sign in to comment.