Sha256: 7fdb34e92babae4962d6edabc7e23726125dd287fc3dc02904846c11be44aba5

Contents?: true

Size: 1.93 KB

Versions: 62

Compression:

Stored size: 1.93 KB

Contents

require 'test_helper'

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

        def qualified_discount
          @item_quantity_discount ||= Product.new(product_ids: ['PRODUCT'])
        end
        alias_method :order_total_discount, :qualified_discount
        alias_method :promo_codes_discount, :qualified_discount
        alias_method :item_quantity_discount, :qualified_discount

        def discounted_order
          @discounted_order ||= Workarea::Order.new.tap do |order|
            order.items.build(product_id: 'PRODUCT')
          end
        end

        def test_item_qualifies
          order = Workarea::Order.new
          item = order.items.build(product_id: 'PRODUCT')

          discount = Product.new(product_ids: ['PRODUCT1'])
          refute(discount.item_qualifies?(item))

          discount = Product.new(product_ids: ['PRODUCT'])
          assert(discount.item_qualifies?(item))
        end

        def test_apply
          order = Workarea::Order.new

          item = order.items.build(product_id: 'PRODUCT1', sku: 'SKU1')
          item.price_adjustments.build(price: 'item', amount: 6.to_m)

          item = order.items.build(
            product_id: 'PRODUCT2',
            sku: 'SKU2',
            quantity: 2
          )
          item.price_adjustments.build(price: 'item', amount: 6.to_m)

            discount = Product.new(
              amount_type: 'percent',
              amount: 50,
              product_ids: ['PRODUCT1']
            )

          discount.apply(order)

          assert_equal(2, order.items.first.price_adjustments.length)
          assert_equal(-3.to_m, order.items.first.price_adjustments.last.amount)
          assert_equal(1, order.items.second.price_adjustments.length)
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.26 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.45 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.25 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.23 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.44 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.22 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.43 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.21 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.42 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.20 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.41 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.19 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.40 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.18 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.39 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.17 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.38 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.16 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.37 test/models/workarea/pricing/discount/product_test.rb