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.4.27 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.4 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.26 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.3 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.25 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.2 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.24 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.1 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.23 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.22 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.0 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.21 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.0.beta.1 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.20 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.19 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.18 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.17 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.16 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.15 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.14 test/models/workarea/pricing/discount/product_test.rb