Sha256: 28141e1f60b9434c9275d3879e09e733d0bdee8dac00f4f5cc64adf31a93327d

Contents?: true

Size: 1.91 KB

Versions: 62

Compression:

Stored size: 1.91 KB

Contents

require 'test_helper'

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

        def qualified_discount
          @qualified_discount ||= FreeGift.new(category_ids: ['CATEGORY'])
        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|
            order.items.build(category_ids: ['CATEGORY'])
          end
        end

        def test_catalog_qualifies?
          order = Workarea::Order.new
          order.items.build(
            product_id: 'PRODUCT',
            category_ids: ['CATEGORY']
          )

          discount = FreeGift.new
          assert(discount.catalog_qualifies?(order))

          discount = FreeGift.new(category_ids: ['CATEGORY1'])
          refute(discount.catalog_qualifies?(order))

          discount = FreeGift.new(category_ids: ['CATEGORY'])
          assert(discount.catalog_qualifies?(order))

          discount = FreeGift.new(product_ids: ['PRODUCT1'])
          refute(discount.catalog_qualifies?(order))

          discount = FreeGift.new(product_ids: ['PRODUCT'])
          assert(discount.catalog_qualifies?(order))

          discount = FreeGift.new(
            product_ids: ['PRODUCT1'],
            category_ids: ['CATEGORY1']
          )
          refute(discount.catalog_qualifies?(order))

          discount = FreeGift.new(
            product_ids: ['PRODUCT'],
            category_ids: ['CATEGORY1']
          )
          assert(discount.catalog_qualifies?(order))

          discount = FreeGift.new(
            product_ids: ['PRODUCT1'],
            category_ids: ['CATEGORY']
          )
          assert(discount.catalog_qualifies?(order))
        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/free_gift_test.rb
workarea-core-3.5.26 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.45 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.25 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.23 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.44 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.22 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.43 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.21 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.42 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.20 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.41 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.19 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.40 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.18 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.39 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.17 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.38 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.5.16 test/models/workarea/pricing/discount/free_gift_test.rb
workarea-core-3.4.37 test/models/workarea/pricing/discount/free_gift_test.rb