|
3 | 3 | describe MDS::Services::SubmitOrder do
|
4 | 4 | subject { described_class.new(sample_credentials) }
|
5 | 5 |
|
| 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 | + |
6 | 44 | describe '#query' do
|
7 | 45 | it "allows for internation characters" do
|
8 | 46 | VCR.use_cassette("submit_internation_order") do
|
|
0 commit comments