Skip to content

Commit 5fd112a

Browse files
committed
Add missing tests for shipment state after cancel
When cancelling all items in a completed order, if the shipment is not already shipped, it should be marked as cancelled. However, if the shipment has already shipped, we should maintain its state because we treat that state as immutable.
1 parent 72f1b5c commit 5fd112a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

core/spec/models/spree/order_cancellations_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,32 @@
109109
it "adjusts the order" do
110110
expect { subject }.to change { order.reload.total }.by(-40.0)
111111
end
112+
113+
context "when cancelling all items in a completed order" do
114+
let!(:order) { create(:completed_order_with_totals, line_items_attributes: [{ quantity: }]) }
115+
116+
subject { described_class.new(order).short_ship(order.inventory_units) }
117+
118+
it "updates all of the inventory units" do
119+
expect { subject }.to change { order.inventory_units.canceled.count }.to(quantity)
120+
end
121+
122+
it "updates the shipment state" do
123+
expect { subject }.to change { order.shipments.first.reload.state }.to("canceled")
124+
end
125+
126+
context "when the shipment is already shipped" do
127+
let!(:order) { create(:shipped_order, line_items_attributes: [{ quantity: }]) }
128+
129+
it "updates all of the inventory units" do
130+
expect { subject }.to change { order.inventory_units.canceled.count }.to(quantity)
131+
end
132+
133+
it "does not update the shipment state" do
134+
expect { subject }.not_to change { order.shipments.first.reload.state }.from("shipped")
135+
end
136+
end
137+
end
112138
end
113139

114140
it "sends a cancellation email" do

0 commit comments

Comments
 (0)