Skip to content

Commit eab176e

Browse files
committed
Spec out integration of shipping notes
1 parent 8f36034 commit eab176e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

spec/mds/services/submit_order_spec.rb

+38
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@
33
describe MDS::Services::SubmitOrder do
44
subject { described_class.new(sample_credentials) }
55

6+
describe '#builder' do
7+
it 'adds shipping instructions to the XML when present in JSON' do
8+
xml = subject.builder(sample_shipment).to_xml
9+
expect( xml ).to match /OrderNotes/
10+
expect( xml ).to match /MustShipBy/
11+
expect( xml ).to match /NoShipBefore/
12+
end
13+
it 'does not add shipping notes to the XML when absent from JSON' do
14+
shipment = sample_shipment.except(:shipping_notes, :must_ship_by, :no_ship_before)
15+
xml = subject.builder( shipment ).to_xml
16+
expect( xml ).to_not match /OrderNotes/
17+
expect( xml ).to_not match /MustShipBy/
18+
expect( xml ).to_not match /NoShipBefore/
19+
end
20+
[:shipping_notes, :must_ship_by, :no_ship_before].each do |key|
21+
it "does not error when #{key} key is missing from JSON" do
22+
expect{ subject.builder sample_shipment.delete_if {|k| k == key }
23+
}.to_not raise_exception
24+
end
25+
it "does not error when #{key} is blank in JSON" do
26+
expect{ subject.builder sample_shipment.merge(key => "")
27+
}.to_not raise_exception
28+
end
29+
end
30+
it "errors when must_ship_by date is invalid" do
31+
expect{ subject.builder sample_shipment.merge(must_ship_by: "2015-08-51T00:00:00")
32+
}.to raise_exception("Error setting up shipping instructions: invalid date")
33+
end
34+
it "replaces ampersands in shipping instructions" do
35+
xml = subject.builder(sample_shipment.merge(shipping_notes: "Pick & pack")).to_xml
36+
expect( xml ).to match /Pick and pack/
37+
end
38+
it "errors when shipping_notes are too long" do
39+
expect{ subject.builder sample_shipment.merge(shipping_notes: "A"*501)
40+
}.to raise_exception
41+
end
42+
end
43+
644
describe '#query' do
745
it "allows for internation characters" do
846
VCR.use_cassette("submit_internation_order") do

spec/support/sample_objects.rb

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def sample_shipment(number = "R#{rand(999999)}")
1414
"email"=>"[email protected]",
1515
"currency"=>"USD",
1616
"placed_on"=>"2014-02-03T17:29:15.219Z",
17+
"shipping_notes"=>"Please fit in large box",
18+
"no_ship_before"=>"2015-08-01T00:00:00+00:00",
19+
"must_ship_by"=>"2015-08-25T00:00:00+00:00",
1720
"totals"=>
1821
{"item"=>200,
1922
"adjustment"=>20,

0 commit comments

Comments
 (0)