From f71fb8b058bea2946c994210956467c4f5aae363 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 27 Jul 2023 17:16:08 +0200 Subject: [PATCH] Improve the flakey `determine_target_shipment` spec - 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. --- core/spec/models/spree/order_inventory_spec.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/spec/models/spree/order_inventory_spec.rb b/core/spec/models/spree/order_inventory_spec.rb index a0d5872d93c..8383322e39d 100644 --- a/core/spec/models/spree/order_inventory_spec.rb +++ b/core/spec/models/spree/order_inventory_spec.rb @@ -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