Sha256: 5c1134dd334f749165766cf4c4d55d1445ff88fd56088d6ba142fbae5ebee576

Contents?: true

Size: 1.74 KB

Versions: 54

Compression:

Stored size: 1.74 KB

Contents

require 'test_helper'

module Workarea
  class Order
    class ItemTest < TestCase
      def item
        @item ||= Order::Item.new
      end

      def test_matches_categories?
        item.category_ids = %w(one two)
        assert(item.matches_categories?('one'))
        assert(item.matches_categories?(%w(one two)))
        refute(item.matches_categories?('three'))
      end

      def test_matches_products?
        item.product_id = 'one'
        assert(item.matches_products?('one'))
        assert(item.matches_products?(%w(one two)))
        refute(item.matches_products?('three'))
      end

      def test_original_unit_price
        item.quantity = 2
        assert_equal(0.to_m, item.original_unit_price)

        item.price_adjustments.build(amount: 4.to_m, quantity: 2)
        assert_equal(2.to_m, item.original_unit_price)
      end

      def test_current_unit_price
        item.quantity = 2
        assert_equal(0.to_m, item.current_unit_price)

        item.price_adjustments.build(amount: 4.to_m, quantity: 2, price: 'item')
        assert_equal(2.to_m, item.current_unit_price)

        item.price_adjustments.build(amount: -0.4.to_m, quantity: 2, price: 'order')
        assert_equal(2.to_m, item.current_unit_price)

        # TODO: v4 look to rework discounts that make partial quantity "free"
        # without affecting misrepresenting current_unit_price.
        item.price_adjustments.build(amount: -2.to_m, quantity: 1, price: 'item')
        assert_equal(1.to_m, item.current_unit_price)
      end

      def test_on_sale?
        refute(item.on_sale?)

        item.price_adjustments.build(
          amount: 4.to_m,
          quantity: 1,
          data: { 'on_sale' => true }
        )
        assert(item.on_sale?)
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
workarea-core-3.4.45 test/models/workarea/order/item_test.rb
workarea-core-3.4.44 test/models/workarea/order/item_test.rb
workarea-core-3.4.43 test/models/workarea/order/item_test.rb
workarea-core-3.4.42 test/models/workarea/order/item_test.rb
workarea-core-3.4.41 test/models/workarea/order/item_test.rb
workarea-core-3.4.40 test/models/workarea/order/item_test.rb
workarea-core-3.5.18 test/models/workarea/order/item_test.rb
workarea-core-3.4.39 test/models/workarea/order/item_test.rb
workarea-core-3.5.17 test/models/workarea/order/item_test.rb
workarea-core-3.4.38 test/models/workarea/order/item_test.rb
workarea-core-3.5.16 test/models/workarea/order/item_test.rb
workarea-core-3.4.37 test/models/workarea/order/item_test.rb
workarea-core-3.5.15 test/models/workarea/order/item_test.rb
workarea-core-3.4.36 test/models/workarea/order/item_test.rb
workarea-core-3.5.14 test/models/workarea/order/item_test.rb
workarea-core-3.4.35 test/models/workarea/order/item_test.rb
workarea-core-3.5.13 test/models/workarea/order/item_test.rb
workarea-core-3.4.34 test/models/workarea/order/item_test.rb
workarea-core-3.5.12 test/models/workarea/order/item_test.rb
workarea-core-3.4.33 test/models/workarea/order/item_test.rb