Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit 0b46473

Browse files
Sarah Langheinrichtorasakura
authored andcommitted
added :purchase_price to shipment as attr_reader
[Trello-Card #7] https://trello.com/c/YJockSpa
1 parent 92656d4 commit 0b46473

File tree

2 files changed

+180
-2
lines changed

2 files changed

+180
-2
lines changed

lib/shipcloud/shipment.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class Shipment < Base
55
include Shipcloud::Operations::All
66

77
attr_accessor :from, :to, :carrier, :package, :reference_number, :metadata
8-
attr_reader :id, :created_at, :carrier_tracking_no, :tracking_url, :label_url, :packages, :price
8+
attr_reader :id, :created_at, :carrier_tracking_no, :tracking_url, :label_url, :packages,
9+
:price, :purchase_price
910

1011
def self.index_response_root
1112
"#{class_name.downcase}s"

spec/shipcloud/shipment_spec.rb

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@
8282
and_return("id" => "123")
8383
Shipcloud::Shipment.find("123")
8484
end
85+
86+
it "makes a new GET request and receives a specific shipment with purchase_price" do
87+
stub_shipment_requests(shipment_response_with_purchase_price)
88+
89+
shipment = Shipcloud::Shipment.find("123")
90+
91+
expect(shipment.purchase_price).not_to be_nil
92+
end
93+
94+
it "makes a new GET request and receives a specific shipment without purchase_price" do
95+
stub_shipment_requests(shipment_response_without_purchase_price)
96+
97+
shipment = Shipcloud::Shipment.find("123")
98+
99+
expect(shipment.purchase_price).to be_nil
100+
end
85101
end
86102

87103
describe ".update" do
@@ -119,6 +135,21 @@
119135
end
120136
end
121137

138+
it "returns a purchase_price if existing of Shipment objects" do
139+
stub_shipments_requests
140+
141+
shipments = Shipcloud::Shipment.all
142+
143+
shipments.each do |shipment|
144+
purchase_price = shipment.purchase_price
145+
if purchase_price
146+
expect(purchase_price).to be_a Hash
147+
else
148+
expect(purchase_price).to be_nil
149+
end
150+
end
151+
end
152+
122153
it "returns a filtered list of Shipment objects when using filter parameters" do
123154
filter = {
124155
"carrier" => "dhl",
@@ -144,6 +175,12 @@ def stub_shipments_requests
144175
and_return("shipments" => shipments_array)
145176
end
146177

178+
def stub_shipment_requests(response)
179+
allow(Shipcloud).to receive(:request).
180+
with(:get, "shipments/123", {}, api_key: nil).
181+
and_return(response)
182+
end
183+
147184
def shipments_array
148185
[
149186
{ "id" => "86afb143f9c9c0cfd4eb7a7c26a5c616585a6271",
@@ -177,7 +214,40 @@ def shipments_array
177214
"width" => 10.0,
178215
"height" => 10.0,
179216
"weight" => 1.5
180-
}
217+
},
218+
"purchase_price" => {
219+
"preliminary" => {
220+
"line_items" => [
221+
{
222+
"amount_net" => 12.90,
223+
"currency" => "EUR",
224+
"category" => "shipping"
225+
},
226+
],
227+
"total" => {
228+
"amount_net" => 12.90,
229+
"currency" => "EUR",
230+
},
231+
},
232+
"invoiced" => {
233+
"line_items" => [
234+
{
235+
"amount_net" => 12.90,
236+
"currency" => "EUR",
237+
"category" => "shipping"
238+
},
239+
{
240+
"amount_net" => 1.60,
241+
"currency" => "EUR",
242+
"category" => "fuel"
243+
},
244+
],
245+
"total" => {
246+
"amount_net" => 14.50,
247+
"currency" => "EUR",
248+
},
249+
},
250+
},
181251
},
182252
{ "id" => "be81573799958587ae891b983aabf9c4089fc462",
183253
"carrier_tracking_no" => "1Z12345E1305277940",
@@ -214,4 +284,111 @@ def shipments_array
214284
}
215285
]
216286
end
287+
288+
def shipment_response_with_purchase_price
289+
{
290+
"id" => "86afb143f9c9c0cfd4eb7a7c26a5c616585a6271",
291+
"carrier_tracking_no" => "43128000105",
292+
"carrier" => "hermes",
293+
"service" => "standard",
294+
"created_at" => "2014-11-12T14:03:45+01:00",
295+
"price" => 3.5,
296+
"tracking_url" => "http://track.shipcloud.dev/de/86afb143f9",
297+
"to" => {
298+
"first_name" => "Hans",
299+
"last_name" => "Meier",
300+
"street" => "Semmelweg",
301+
"street_no" => "1",
302+
"zip_code" => "12345",
303+
"city" => "Hamburg",
304+
"country" => "DE"
305+
},
306+
"from" => {
307+
"company" => "webionate GmbH",
308+
"last_name" => "Fahlbusch",
309+
"street" => "Lüdmoor",
310+
"street_no" => "35a",
311+
"zip_code" => "22175",
312+
"city" => "Hamburg",
313+
"country" => "DE"
314+
},
315+
"packages" => {
316+
"id" => "be81573799958587ae891b983aabf9c4089fc462",
317+
"length" => 10.0,
318+
"width" => 10.0,
319+
"height" => 10.0,
320+
"weight" => 1.5
321+
},
322+
"purchase_price" => {
323+
"preliminary" => {
324+
"line_items" => [
325+
{
326+
"amount_net" => 12.90,
327+
"currency" => "EUR",
328+
"category" => "shipping"
329+
},
330+
],
331+
"total" => {
332+
"amount_net" => 12.90,
333+
"currency" => "EUR",
334+
},
335+
},
336+
"invoiced" => {
337+
"line_items" => [
338+
{
339+
"amount_net" => 12.90,
340+
"currency" => "EUR",
341+
"category" => "shipping"
342+
},
343+
{
344+
"amount_net" => 1.60,
345+
"currency" => "EUR",
346+
"category" => "fuel"
347+
},
348+
],
349+
"total" => {
350+
"amount_net" => 14.50,
351+
"currency" => "EUR",
352+
},
353+
},
354+
},
355+
}
356+
end
357+
358+
def shipment_response_without_purchase_price
359+
{
360+
"id" => "be81573799958587ae891b983aabf9c4089fc462",
361+
"carrier_tracking_no" => "1Z12345E1305277940",
362+
"carrier" => "ups",
363+
"service" => "standard",
364+
"created_at" => "2014-11-12T14:03:45+01:00",
365+
"price" => 3.0,
366+
"tracking_url" => "http://track.shipcloud.dev/de/be598a2fd2",
367+
"to" => {
368+
"first_name" => "Test",
369+
"last_name" => "Kunde",
370+
"street" => "Gluckstr.",
371+
"street_no" => "57",
372+
"zip_code" => "22081",
373+
"city" => "Hamburg",
374+
"country" => "DE"
375+
},
376+
"from" => {
377+
"company" => "webionate GmbH",
378+
"last_name" => "Fahlbusch",
379+
"street" => "Lüdmoor",
380+
"street_no" => "35a",
381+
"zip_code" => "22175",
382+
"city" => "Hamburg",
383+
"country" => "DE"
384+
},
385+
"packages" => {
386+
"id" => "74d4f1fc193d8a7ca542d1ee4e2021f3ddb82242",
387+
"length" => 15.0,
388+
"width" => 20.0,
389+
"height" => 10.0,
390+
"weight" => 2.0
391+
}
392+
}
393+
end
217394
end

0 commit comments

Comments
 (0)