Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5423a0e

Browse files
benjaminwiljarednormankjrigaadammathysAlistairNorman
committedApr 10, 2025·
WIP: high-level integration test for legacy promotion system
Co-authored-by: Jared Norman <[email protected]> Co-authored-by: Kendra Riga <[email protected]> Co-authored-by: Adam Mueller <[email protected]> Co-authored-by: Alistair Norman <[email protected]> Co-authored-by: Senem Soy <[email protected]> Co-authored-by: Sofia Besenski <[email protected]>
1 parent 625b699 commit 5423a0e

File tree

2 files changed

+64
-13
lines changed

2 files changed

+64
-13
lines changed
 

‎legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_order_updater_patch.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def update_item_totals
4141
)
4242
end
4343
end
44-
Spree::OrderUpdater.prepend self
44+
45+
# FIXME: We need to verify that this is the right thing to do?
46+
Spree::Config.order_recalculator_class.prepend self
4547
end
4648
end

‎legacy_promotions/spec/models/spree/promotion_integration_spec.rb

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,72 @@
232232
order.complete
233233
}.to change{ promo_adjustment.reload.eligible }.to(false)
234234
end
235+
end
235236

236-
it "adjusts the promo_total" do
237-
expect{
238-
order.complete
239-
}.to change(order, :promo_total).by(10)
237+
describe "checking whether a promotion code is still eligible after one use" do
238+
let(:promotion) do
239+
FactoryBot.create(
240+
:promotion,
241+
:with_order_adjustment,
242+
code: "discount",
243+
per_code_usage_limit: 1,
244+
weighted_order_adjustment_amount: 10
245+
)
246+
end
247+
let(:code) { promotion.codes.first }
248+
let(:order) do
249+
FactoryBot.create(:order_with_line_items, line_items_price: 40, shipment_cost: 0).tap do |order|
250+
FactoryBot.create(:payment, amount: 30, order:)
251+
promotion.activate(order:, promotion_code: code)
252+
end
240253
end
254+
let(:promo_adjustment) { order.adjustments.promotion.first }
241255

242-
it "increases the total to remove the promo" do
243-
expect{
244-
order.complete
245-
}.to change(order, :total).from(30).to(40)
256+
before do
257+
order.next! until order.can_complete?
258+
259+
FactoryBot.create(:order_with_line_items, line_items_price: 40, shipment_cost: 0).tap do |order|
260+
FactoryBot.create(:payment, amount: 30, order:)
261+
promotion.activate(order:, promotion_code: code)
262+
order.next! until order.can_complete?
263+
order.complete!
264+
end
246265
end
247266

248-
it "resets the state of the order" do
249-
expect{
250-
order.complete
251-
}.to change{ order.reload.state }.from("confirm").to("address")
267+
context 'with the in-memory order updater' do
268+
subject { order.recalculate(persist: false) }
269+
270+
around do |example|
271+
default_order_recalculator = Spree::Config.order_recalculator_class.to_s
272+
273+
Spree::Config.order_recalculator_class = 'Spree::InMemoryOrderUpdater'
274+
275+
example.run
276+
277+
Spree::Config.order_recalculator_class = default_order_recalculator
278+
end
279+
280+
it "makes the promotion ineligible" do
281+
expect { subject }
282+
.to change { order.adjustments.first.eligible }
283+
.from(true)
284+
.to(false)
285+
286+
expect(promo_adjustment.reload.eligible).to eq true
287+
end
288+
289+
it "adjusts the promo_total" do
290+
expect { subject }.to change { order.promo_total }.from(-10).to(0)
291+
292+
expect(order.reload.promo_total).to eq -10
293+
end
294+
295+
it "increases the total to remove the promo",
296+
pending: "This failure points to a real issue we have with the in-memory order updater" do
297+
expect { subject }.to change { order.total }.from(30).to(40)
298+
299+
expect(order.reload.total).to eq 40
300+
end
252301
end
253302
end
254303

0 commit comments

Comments
 (0)