Skip to content

Commit

Permalink
Improve the flakey determine_target_shipment spec
Browse files Browse the repository at this point in the history
- Explicitly set the count on hand
- Add pre-flight expectations
- Aggregate failures

The flakeyness is very hard to reproduce and if the supposed fixes
won't have an effect at least this should give use more information
on why it failed.
  • Loading branch information
elia committed Jul 27, 2023
1 parent af562d1 commit f71fb8b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions core/spec/models/spree/order_inventory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,21 @@
end

context 'when there is not enough availability at any stock location' do
before { stock_item.set_count_on_hand 0 }

it 'falls-back selecting first non-shipped shipment that leaves from same stock_location' do
shipment = subject.send(:determine_target_shipment, 1)
required_quantity = 1
shipment = subject.send(:determine_target_shipment, required_quantity)
shipment.reload

expect(shipment.shipped?).to be false
expect(shipment.inventory_units_for(variant)).to be_empty
expect(variant.stock_location_ids.include?(shipment.stock_location_id)).to be true
expect(shipment.stock_location).not_to eql stock_item.stock_location
aggregate_failures do
expect(stock_item.count_on_hand).to eq(0)
expect(stock_item.backorderable?).to eq(false)
expect(shipment.shipped?).to be false
expect(shipment.inventory_units_for(variant)).to be_empty
expect(variant.stock_location_ids.include?(shipment.stock_location_id)).to be true
expect(shipment.stock_location).not_to eql stock_item.stock_location
end
end
end
end
Expand Down

0 comments on commit f71fb8b

Please sign in to comment.