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