Sha256: 20cacf0d35eef541c1fcff167a7472a159bc3829683070d7e2b20cedd526e238

Contents?: true

Size: 2 KB

Versions: 62

Compression:

Stored size: 2 KB

Contents

require 'test_helper'

module Workarea
  module Pricing
    class Discount
      class ShippingTest < TestCase
        include DiscountConditionTests::OrderTotal
        include DiscountConditionTests::PromoCodes

        def qualified_discount
          @qualified_discount ||= Shipping.new(shipping_service: 'Ground')
        end
        alias_method :order_total_discount, :qualified_discount
        alias_method :promo_codes_discount, :qualified_discount

        def discounted_order
          @discounted_order ||= Workarea::Order.new.tap do |order|
            shipping = Workarea::Shipping.new(order_id: order.id)
            shipping.set_shipping_service(
              name: 'Ground',
              base_price: 10.to_m
            )
          end
        end

        def order
          @order ||= Workarea::Order.new
        end

        def shipping
          @shipping ||= Workarea::Shipping.new.tap do |shipping|
            shipping.set_shipping_service(
              name: 'Ground',
              base_price: 10.to_m
            )
          end
        end

        def discount_order
          @discount_order ||= Discount::Order.new(order, shipping)
        end

        def test_matching_shipping_service?
          discount = Shipping.new(shipping_service: 'Next Day')
          refute(discount.matching_shipping_service?(discount_order))

          discount = Shipping.new(shipping_service: 'Ground')
          assert(discount.matching_shipping_service?(discount_order))
        end

        def test_apply
          discount = Shipping.new(amount: 7.to_m, shipping_service: 'Ground')
          discount.apply(discount_order)

          price_adjustment = shipping.price_adjustments.last
          assert_equal(-3.to_m, price_adjustment.amount)

          shipping.reset_adjusted_shipping_pricing
          discount = Shipping.new(amount: 11.to_m, shipping_service: 'Ground')
          discount.apply(discount_order)

          assert_equal(1, shipping.price_adjustments.length)
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.36 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.14 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.35 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.13 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.34 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.12 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.33 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.11 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.10 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.32 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.9 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.31 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.8 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.30 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.7 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.29 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.6 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.4.28 test/models/workarea/pricing/discount/shipping_test.rb
workarea-core-3.5.5 test/models/workarea/pricing/discount/shipping_test.rb