Skip to content

Commit 328c836

Browse files
committed
Add specs for shipments
1 parent d5d5bf7 commit 328c836

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

api/spec/requests/spree/api/shipments_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ module Spree::Api
9292
expect(json_response['stock_location_name']).to eq(stock_location.name)
9393
end
9494

95+
it "can update a shipment and it's metadata" do
96+
params = {
97+
shipment: {
98+
stock_location_id: stock_location.to_param,
99+
admin_metadata: { 'delivery_type' => 'express' },
100+
customer_metadata: { 'timing' => 'standard' }
101+
}
102+
}
103+
104+
put(spree.api_shipment_path(shipment), params:)
105+
106+
expect(response.status).to eq(200)
107+
expect(json_response['stock_location_name']).to eq(stock_location.name)
108+
expect(json_response["admin_metadata"]).to eq({ 'delivery_type' => 'express' })
109+
expect(json_response["customer_metadata"]).to eq({ 'timing' => 'standard' })
110+
end
111+
95112
it "can make a shipment ready" do
96113
allow_any_instance_of(Spree::Order).to receive_messages(paid?: true, complete?: true)
97114
put spree.ready_api_shipment_path(shipment)

core/spec/models/spree/shipment_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,4 +872,24 @@
872872

873873
it { is_expected.to include carton }
874874
end
875+
876+
describe "metadata fields" do
877+
it "responds to customer_metadata" do
878+
expect(shipment).to respond_to(:customer_metadata)
879+
end
880+
881+
it "responds to admin_metadata" do
882+
expect(shipment).to respond_to(:admin_metadata)
883+
end
884+
885+
it "can store data in customer_metadata" do
886+
shipment.customer_metadata = { "tracking_info" => "UPS123456789" }
887+
expect(shipment.customer_metadata["tracking_info"]).to eq("UPS123456789")
888+
end
889+
890+
it "can store data in admin_metadata" do
891+
shipment.admin_metadata = { "internal_note" => "Handle with care" }
892+
expect(shipment.admin_metadata["internal_note"]).to eq("Handle with care")
893+
end
894+
end
875895
end

0 commit comments

Comments
 (0)