Sha256: 191bfcdae088926aceb971dd3a1fdcbad3aded28333bb7a4d6fe04688a9e96b9

Contents?: true

Size: 1.93 KB

Versions: 5

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

require 'rails_helper'
require 'shared_examples/calculator_shared_examples'

module Spree
  module Calculator::Shipping
    RSpec.describe FlexiRate, type: :model do
      let(:variant1) { build(:variant, price: 10) }
      let(:variant2) { build(:variant, price: 20) }

      it_behaves_like 'a calculator with a description'

      let(:package) do
        build(:stock_package, variants_contents: { variant1 => 4, variant2 => 6 })
      end

      let(:subject) { described_class.new }

      context "compute" do
        it "should compute amount correctly when all fees are 0" do
          expect(subject.compute(package).round(2)).to eq(0.0)
        end

        it "should compute amount correctly when first_item has a value" do
          subject.preferred_first_item = 1.0
          expect(subject.compute(package).round(2)).to eq(1.0)
        end

        it "should compute amount correctly when additional_items has a value" do
          subject.preferred_additional_item = 1.0
          expect(subject.compute(package).round(2)).to eq(9.0)
        end

        it "should compute amount correctly when additional_items and first_item have values" do
          subject.preferred_first_item = 5.0
          subject.preferred_additional_item = 1.0
          expect(subject.compute(package).round(2)).to eq(14.0)
        end

        it "should compute amount correctly when additional_items and first_item have values AND max items has value" do
          subject.preferred_first_item = 5.0
          subject.preferred_additional_item = 1.0
          subject.preferred_max_items = 3
          expect(subject.compute(package).round(2)).to eq(26.0)
        end

        it "should allow creation of new object with all the attributes" do
          described_class.new(preferred_first_item: 1,
                        preferred_additional_item: 1,
                        preferred_max_items: 1)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/calculator/shipping/flexi_rate_spec.rb
solidus_core-2.10.3 spec/models/spree/calculator/shipping/flexi_rate_spec.rb
solidus_core-2.10.2 spec/models/spree/calculator/shipping/flexi_rate_spec.rb
solidus_core-2.10.1 spec/models/spree/calculator/shipping/flexi_rate_spec.rb
solidus_core-2.10.0 spec/models/spree/calculator/shipping/flexi_rate_spec.rb