Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep backorders when splitting part of variant to new shipment with same SL #5670

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Extract shared example for later reuse
These specs don't really require a specific first level scenario,
so we're first extracting them to a shared example, and with the
following commit we're going to use it in other existing scenarios.
spaghetticode committed Mar 7, 2024
commit 0079208dbc1f03599f8350c26c6857e48c647fe7
48 changes: 25 additions & 23 deletions core/spec/models/spree/fulfilment_changer_spec.rb
Original file line number Diff line number Diff line change
@@ -81,45 +81,47 @@
end
end

subject { shipment_splitter.run! }

before do
variant.stock_items.first.update_column(:count_on_hand, 100)
end

context "when the current shipment stock location is the same of the target shipment" do
let(:current_shipment_inventory_unit_count) { 1 }
let(:quantity) { current_shipment_inventory_unit_count }

shared_examples_for "properly manages inventory units" do
context "when the stock location is empty" do
before do
variant.stock_items.first.update_column(:count_on_hand, 0)
end
let(:stock_item) { variant.stock_items.find_by!(stock_location: current_shipment.stock_location) }

before { stock_item.update_column(:count_on_hand, 0) }

context "when the inventory unit is backordered" do
context "when there are backordered inventory units" do
before do
current_shipment.inventory_units.first.update state: :backordered
current_shipment.inventory_units.first.update(state: :backordered)
end

it "creates a new backordered inventory unit" do
subject
expect(desired_shipment.inventory_units.first).to be_backordered
it "doesn't change the order inventory units state" do
expect { subject }.not_to change { order.inventory_units.map(&:state).sort }
end
end

context "when the inventory unit is on hand" do
context "when all inventory units are on hand" do
before do
current_shipment.inventory_units.first.update state: :on_hand
current_shipment.inventory_units.update_all(state: :on_hand)
end

it "creates a new on hand inventory unit" do
subject
expect(desired_shipment.inventory_units.first).to be_on_hand
it "doesn't change the order inventory units state" do
expect { subject }.not_to change { order.inventory_units.map(&:state).sort }
end
end
end
end

subject { shipment_splitter.run! }

before do
variant.stock_items.first.update_column(:count_on_hand, 100)
end

context "when the current shipment stock location is the same of the target shipment" do
let(:current_shipment_inventory_unit_count) { 1 }
let(:quantity) { current_shipment_inventory_unit_count }

it_behaves_like "properly manages inventory units"
end

context "when tracking inventory is not set (same as false)" do
let(:current_shipment_inventory_unit_count) { 2 }
let(:quantity) { 1 }