Sha256: cf740a3d9ac578b57b72cfc4b99d067cc782482fdd885c55e6850bd51c44a222

Contents?: true

Size: 1.77 KB

Versions: 62

Compression:

Stored size: 1.77 KB

Contents

require 'test_helper'

module Workarea
  class CartCleanerTest < Workarea::TestCase
    setup do
      @order = create_order
      @cleaner = CartCleaner.new(@order)
    end

    def test_removing_non_existent_products
      @order.add_item(product_id: 'foo', sku: 'bar')
      @cleaner.clean
      assert_empty(@order.items)
    end

    def test_removing_non_purchasable_products
      product = create_product(
        purchasable: false,
        variants: [
          { sku: 'SKU1', regular: 5.00 },
          { sku: 'SKU2', regular: 5.00 }
        ]
      )
      @order.add_item(product_id: product.id, sku: product.skus.first)
      @order.add_item(product_id: product.id, sku: product.skus.second)

      @cleaner.clean
      assert_empty(@order.items)
    end

    def test_removing_inactive_variant_items
      product = create_product(
        purchasable: true,
        variants: [
          { sku: 'SKU1', regular: 5.00, active: false },
          { sku: 'SKU2', regular: 5.00 }
        ]
      )
      @order.add_item(product_id: product.id, sku: product.skus.first)
      @order.add_item(product_id: product.id, sku: product.skus.second)

      @cleaner.clean
      assert_equal(1, @order.items.count)
    end

    def test_removing_items_missing_price
      product = Catalog::Product.create!(
        name: 'Integration Product',
        variants: [sku: 'SKU']
      )

      @order.add_item(product_id: product.id, sku: product.skus.first)
      @cleaner.clean
      assert_empty(@order.items)
    end

    def test_messaging
      product = create_product(purchasable: false)
      @order.add_item(product_id: product.id, sku: product.skus.first)

      @cleaner.clean
      assert_equal(@cleaner.messages.length, 1)
      assert(@cleaner.messages.first.include?(product.id))
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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