Skip to content

Commit 1897dc0

Browse files
Noah-Silveraforkata
authored andcommitted
WIP: Improving the dry run functionality before implementing persist
How dry run behaves is not consistent, and we think we can make not persisting easier if we first update the dry run functionality.
1 parent 0517894 commit 1897dc0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

promotions/app/models/solidus_promotions/order_adjuster/discount_order.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def call
1717
SolidusPromotions::Promotion.ordered_lanes.each_key do |lane|
1818
lane_promotions = promotions.select { |promotion| promotion.lane == lane }
1919
lane_benefits = eligible_benefits_for_promotable(lane_promotions.flat_map(&:benefits), order)
20+
# TODO: - (Noah & Sofia) think we should actually build/mark_for_destruction line items make/removed by CreateDiscountedItem on a dry run, and that's an improvement that would make implementing the persist flag easier also
2021
perform_order_benefits(lane_benefits, lane) unless dry_run
2122
line_item_discounts = adjust_line_items(lane_benefits)
2223
shipment_discounts = adjust_shipments(lane_benefits)

promotions/spec/models/solidus_promotions/order_adjuster_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
require "rails_helper"
44

55
RSpec.describe SolidusPromotions::OrderAdjuster, type: :model do
6-
subject(:order_adjuster) { described_class.new(order) }
6+
subject(:order_adjuster) { described_class.new(order, dry_run_promotion: dry_run_promotion) }
77

8+
let(:dry_run_promotion) { nil }
89
let(:line_item) { create(:line_item) }
910
let(:order) { line_item.order }
1011
let(:promotion) { create(:solidus_promotion, apply_automatically: true) }
@@ -31,6 +32,26 @@
3132
expect(order.line_items.last.adjustments.promotion.first&.amount).to eq(-10)
3233
end
3334

35+
context 'when on a dry run' do
36+
let(:dry_run_promotion) { create(:solidus_promotion, :with_adjustable_benefit, promotion_benefit_class: SolidusPromotions::Benefits::CreateDiscountedItem) }
37+
38+
subject do
39+
benefit
40+
order_adjuster.call
41+
end
42+
43+
it 'builds the line item but does not save it' do
44+
expect {
45+
subject
46+
}.to change { order.line_items.length }.by(1)
47+
48+
pending "currently on a dry run this just doesn't happen"
49+
expect(order.line_items.last.variant).to eq(variant)
50+
expect(order.line_items.last.adjustments.promotion.first&.amount).to eq(-10)
51+
52+
expect(order.reload.line_items.length).to eq(1)
53+
end
54+
end
3455
end
3556

3657
context "adjusting line items" do

0 commit comments

Comments
 (0)