|
73 | 73 | end |
74 | 74 | end |
75 | 75 |
|
| 76 | + describe "#previous_lane_discounts" do |
| 77 | + let(:order) { Spree::Order.new } |
| 78 | + let(:tax_rate) { create(:tax_rate) } |
| 79 | + let(:pre_lane_promotion) { create(:solidus_promotion, :with_adjustable_benefit, lane: :pre) } |
| 80 | + let(:post_lane_promotion) { create(:solidus_promotion, :with_adjustable_benefit, lane: :post) } |
| 81 | + let(:line_item) { Spree::LineItem.new(adjustments:, order:) } |
| 82 | + let(:adjustments) { [tax_adjustment, pre_lane_adjustment, post_lane_adjustment] } |
| 83 | + let(:tax_adjustment) { Spree::Adjustment.new(source: tax_rate, amount: 2) } |
| 84 | + let(:pre_lane_adjustment) { Spree::Adjustment.new(source: pre_lane_promotion.benefits.first) } |
| 85 | + let(:post_lane_adjustment) { Spree::Adjustment.new(source: post_lane_promotion.benefits.first) } |
| 86 | + |
| 87 | + subject { line_item.previous_lane_discounts } |
| 88 | + |
| 89 | + it "raises unless we're doing a promotion calculation" do |
| 90 | + expect { subject }.to raise_exception(SolidusPromotions::NotCalculatingPromotions) |
| 91 | + end |
| 92 | + |
| 93 | + context "while calculating promotions" do |
| 94 | + around do |example| |
| 95 | + SolidusPromotions::Promotion.within_lane(lane) do |
| 96 | + example.run |
| 97 | + end |
| 98 | + end |
| 99 | + |
| 100 | + let(:lane) { "pre" } |
| 101 | + it { is_expected.to be_empty } |
| 102 | + |
| 103 | + context "if lane is default" do |
| 104 | + let(:lane) { "default" } |
| 105 | + |
| 106 | + it { is_expected.to contain_exactly(pre_lane_adjustment) } |
| 107 | + end |
| 108 | + |
| 109 | + context "if lane is post" do |
| 110 | + let(:lane) { "post" } |
| 111 | + |
| 112 | + it { is_expected.to contain_exactly(pre_lane_adjustment) } |
| 113 | + end |
| 114 | + end |
| 115 | + end |
| 116 | + |
| 117 | + describe "#current_lane_discounts" do |
| 118 | + let(:order) { Spree::Order.new } |
| 119 | + let(:tax_rate) { create(:tax_rate) } |
| 120 | + let(:pre_lane_promotion) { create(:solidus_promotion, :with_adjustable_benefit, lane: :pre) } |
| 121 | + let(:post_lane_promotion) { create(:solidus_promotion, :with_adjustable_benefit, lane: :post) } |
| 122 | + let(:line_item) { Spree::LineItem.new(adjustments:, order:) } |
| 123 | + let(:adjustments) { [tax_adjustment, pre_lane_adjustment, post_lane_adjustment] } |
| 124 | + let(:tax_adjustment) { Spree::Adjustment.new(source: tax_rate, amount: 2) } |
| 125 | + let(:pre_lane_adjustment) { Spree::Adjustment.new(source: pre_lane_promotion.benefits.first) } |
| 126 | + let(:post_lane_adjustment) { Spree::Adjustment.new(source: post_lane_promotion.benefits.first) } |
| 127 | + |
| 128 | + subject { line_item.current_lane_discounts } |
| 129 | + |
| 130 | + it "raises unless we're doing a promotion calculation" do |
| 131 | + expect { subject }.to raise_exception(SolidusPromotions::NotCalculatingPromotions) |
| 132 | + end |
| 133 | + |
| 134 | + context "while calculating promotions" do |
| 135 | + around do |example| |
| 136 | + SolidusPromotions::Promotion.within_lane(lane) do |
| 137 | + example.run |
| 138 | + end |
| 139 | + end |
| 140 | + |
| 141 | + let(:lane) { "pre" } |
| 142 | + it { is_expected.to contain_exactly(pre_lane_adjustment) } |
| 143 | + |
| 144 | + context "if lane is default" do |
| 145 | + let(:lane) { "default" } |
| 146 | + |
| 147 | + it { is_expected.to be_empty } |
| 148 | + end |
| 149 | + |
| 150 | + context "if lane is post" do |
| 151 | + let(:lane) { "post" } |
| 152 | + |
| 153 | + it { is_expected.to contain_exactly(post_lane_adjustment) } |
| 154 | + end |
| 155 | + end |
| 156 | + end |
| 157 | + |
76 | 158 | describe "changing quantities" do |
77 | 159 | context "when line item is managed by an automation" do |
78 | 160 | let(:order) { create(:order) } |
|
0 commit comments