Sha256: c0b36dcec3b06c3347a38055b0248930288643b1e20a98ef9e4d3979fd75ac82

Contents?: true

Size: 1.43 KB

Versions: 48

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

module Spree
  module PromotionHandler
    RSpec.describe Page, type: :model do
      let(:order) { create(:order_with_line_items, line_items_count: 1) }

      let(:promotion) { Promotion.create(name: "10% off", path: '10off') }
      before do
        calculator = Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
        action = Promotion::Actions::CreateItemAdjustments.create(calculator: calculator)
        promotion.actions << action
      end

      it "activates at the right path" do
        expect(order.line_item_adjustments.count).to eq(0)
        Spree::PromotionHandler::Page.new(order, '10off').activate
        expect(order.line_item_adjustments.count).to eq(1)
      end

      context "when promotion is expired" do
        before do
          promotion.update_columns(
            starts_at: 1.week.ago,
            expires_at: 1.day.ago
          )
        end

        it "is not activated" do
          expect(order.line_item_adjustments.count).to eq(0)
          Spree::PromotionHandler::Page.new(order, '10off').activate
          expect(order.line_item_adjustments.count).to eq(0)
        end
      end

      it "does not activate at the wrong path" do
        expect(order.line_item_adjustments.count).to eq(0)
        Spree::PromotionHandler::Page.new(order, 'wrongpath').activate
        expect(order.line_item_adjustments.count).to eq(0)
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.10.3 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.10.2 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.6 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.8.6 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.10.1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.5 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.10.0 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.4 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.6.6 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.7.4 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.8.5 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.3 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.2 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.7.3 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.6.5 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.0 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/promotion_handler/page_spec.rb