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.15 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.36 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.14 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.35 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.13 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.34 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.12 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.33 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.11 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.10 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.32 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.9 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.31 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.8 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.30 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.7 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.29 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.6 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.4.28 test/models/workarea/pricing/discount/product_test.rb
workarea-core-3.5.5 test/models/workarea/pricing/discount/product_test.rb