|
82 | 82 | end |
83 | 83 |
|
84 | 84 | shared_examples_for "properly manages inventory units" do |
85 | | - context "when the stock location is empty" do |
86 | | - let(:stock_item) { variant.stock_items.find_by!(stock_location: current_shipment.stock_location) } |
| 85 | + let(:stock_item) { variant.stock_items.find_by!(stock_location: current_shipment.stock_location) } |
87 | 86 |
|
88 | | - before { stock_item.update_column(:count_on_hand, 0) } |
| 87 | + context "when there are backordered inventory units" do |
| 88 | + let(:backordered_units_count) { 1 } |
89 | 89 |
|
90 | | - context "when there are backordered inventory units" do |
| 90 | + before do |
| 91 | + current_shipment.inventory_units.limit(backordered_units_count).update!(state: :backordered) |
| 92 | + end |
| 93 | + |
| 94 | + context "when the stock is zero or negative" do |
91 | 95 | before do |
92 | | - current_shipment.inventory_units.first.update(state: :backordered) |
| 96 | + stock_item.update_column(:count_on_hand, -backordered_units_count) |
93 | 97 | end |
94 | 98 |
|
95 | | - it "doesn't change the order inventory units state" do |
96 | | - expect { subject }.not_to change { order.inventory_units.map(&:state).sort } |
| 99 | + it "doesn't change inventory units state" do |
| 100 | + expect { subject } |
| 101 | + .not_to change { order.inventory_units.map(&:state).sort } |
| 102 | + .from(%w[backordered on_hand]) |
97 | 103 | end |
98 | 104 | end |
99 | 105 |
|
100 | | - context "when all inventory units are on hand" do |
| 106 | + context "when backordered items can become on hand" do |
| 107 | + before do |
| 108 | + stock_item.update_column(:count_on_hand, backordered_units_count) |
| 109 | + end |
| 110 | + |
| 111 | + it "makes all inventory units on hand" do |
| 112 | + expect { subject } |
| 113 | + .to change { order.inventory_units.map(&:state).sort } |
| 114 | + .from(%w[backordered on_hand]).to(%w[on_hand on_hand]) |
| 115 | + end |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + context "when all inventory units are on hand" do |
| 120 | + before do |
| 121 | + current_shipment.inventory_units.update_all(state: :on_hand) |
| 122 | + end |
| 123 | + |
| 124 | + context "when the stock is negative" do |
101 | 125 | before do |
102 | | - current_shipment.inventory_units.update_all(state: :on_hand) |
| 126 | + stock_item.update_column(:count_on_hand, -1) |
103 | 127 | end |
104 | 128 |
|
105 | 129 | it "doesn't change the order inventory units state" do |
106 | 130 | expect { subject }.not_to change { order.inventory_units.map(&:state).sort } |
107 | 131 | end |
108 | 132 | end |
109 | 133 | end |
| 134 | + |
| 135 | + context "when the stock location is empty" do |
| 136 | + before { stock_item.update_column(:count_on_hand, 0) } |
| 137 | + |
| 138 | + it "doesn't change the order inventory units state" do |
| 139 | + expect { subject }.not_to change { order.inventory_units.map(&:state).sort } |
| 140 | + end |
| 141 | + end |
110 | 142 | end |
111 | 143 |
|
112 | 144 | subject { shipment_splitter.run! } |
|
115 | 147 | variant.stock_items.first.update_column(:count_on_hand, 100) |
116 | 148 | end |
117 | 149 |
|
118 | | - context "when the current shipment stock location is the same of the target shipment" do |
119 | | - let(:current_shipment_inventory_unit_count) { 1 } |
120 | | - let(:quantity) { current_shipment_inventory_unit_count } |
| 150 | + context "when tracking inventory (default behavior)" do |
| 151 | + let(:current_shipment_inventory_unit_count) { 2 } |
| 152 | + let(:quantity) { 1 } |
121 | 153 |
|
| 154 | + it_behaves_like "moves inventory units between shipments" |
122 | 155 | it_behaves_like "properly manages inventory units" |
123 | 156 | end |
124 | 157 |
|
|
366 | 399 | let(:desired_shipment) { order.shipments.build(stock_location: current_shipment.stock_location) } |
367 | 400 |
|
368 | 401 | it_behaves_like "moves inventory units between shipments" |
| 402 | + it_behaves_like "properly manages inventory units" |
369 | 403 |
|
370 | 404 | context "if the desired shipment is invalid" do |
371 | 405 | let(:desired_shipment) { order.shipments.build(stock_location_id: 99_999_999) } |
|
0 commit comments