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