|
36 | 36 | end |
37 | 37 | end |
38 | 38 | end |
| 39 | + |
| 40 | + describe "#discounts_by_lanes" do |
| 41 | + let(:tax_rate) { create(:tax_rate) } |
| 42 | + let(:pre_lane_promotion) { create(:solidus_promotion, :with_adjustable_benefit, lane: :pre) } |
| 43 | + let(:post_lane_promotion) { create(:solidus_promotion, :with_adjustable_benefit, lane: :post) } |
| 44 | + let(:shipment) { Spree::Shipment.new(adjustments:) } |
| 45 | + let(:adjustments) { [tax_adjustment, pre_lane_adjustment, post_lane_adjustment] } |
| 46 | + let(:tax_adjustment) { Spree::Adjustment.new(source: tax_rate, amount: 2) } |
| 47 | + let(:pre_lane_adjustment) { Spree::Adjustment.new(source: pre_lane_promotion.benefits.first) } |
| 48 | + let(:post_lane_adjustment) { Spree::Adjustment.new(source: post_lane_promotion.benefits.first) } |
| 49 | + |
| 50 | + subject { shipment.discounts_by_lanes(lanes) } |
| 51 | + |
| 52 | + context "if lanes is empty" do |
| 53 | + let(:lanes) { [] } |
| 54 | + it { is_expected.to be_empty } |
| 55 | + end |
| 56 | + |
| 57 | + context "if lanes is all lanes" do |
| 58 | + let(:lanes) { SolidusPromotions::Promotion.ordered_lanes } |
| 59 | + |
| 60 | + it { is_expected.to contain_exactly(pre_lane_adjustment, post_lane_adjustment) } |
| 61 | + end |
| 62 | + |
| 63 | + context "if lanes is only pre lane" do |
| 64 | + let(:lanes) { [:pre] } |
| 65 | + |
| 66 | + it { is_expected.to contain_exactly(pre_lane_adjustment) } |
| 67 | + end |
| 68 | + |
| 69 | + context "if lanes is only default lane" do |
| 70 | + let(:lanes) { [:default] } |
| 71 | + |
| 72 | + it { is_expected.to be_empty } |
| 73 | + end |
| 74 | + end |
| 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(:shipment) { Spree::Shipment.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 { shipment.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(:shipment) { Spree::Shipment.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 { shipment.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 |
39 | 157 | end |
0 commit comments