Sha256: 2d416e6b2f5786a90fb84c7731a849b96be278365c1c34d33cb9381eeccccae8

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require 'rails_helper'
require 'shared_examples/calculator_shared_examples'

module Spree
  module Calculator::Shipping
    RSpec.describe FlatPercentItemTotal, type: :model do
      it_behaves_like 'a calculator with a description'

      let(:line_item1) { build(:line_item, price: 10.11) }
      let(:line_item2) { build(:line_item, price: 20.2222) }

      let(:inventory_unit1) { build(:inventory_unit, line_item: line_item1) }
      let(:inventory_unit2) { build(:inventory_unit, line_item: line_item2) }

      let(:package) do
        build(
          :stock_package,
          contents: [
            Spree::Stock::ContentItem.new(inventory_unit1),
            Spree::Stock::ContentItem.new(inventory_unit1),
            Spree::Stock::ContentItem.new(inventory_unit2),
          ]
        )
      end

      subject { FlatPercentItemTotal.new(preferred_flat_percent: 10) }

      it "should round result correctly" do
        expect(subject.compute(package)).to eq(4.04)
      end

      it "should round result based on order currency" do
        package.order.currency = 'JPY'
        expect(subject.compute(package)).to eq(4)
      end

      it "should return a bigdecimal" do
        expect(subject.compute(package)).to be_a(BigDecimal)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
solidus_core-2.9.6 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.8.6 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.9.5 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.9.4 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.8.5 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.9.3 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.9.2 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.9.1 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.9.0 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.8.4 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.8.3 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.8.2 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.8.1 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb
solidus_core-2.8.0 spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb