Sha256: 7ff97984c10a5dfd195fa2233ca622c172ec5190b1fd822157fd229a0e7b3d05

Contents?: true

Size: 1.32 KB

Versions: 62

Compression:

Stored size: 1.32 KB

Contents

require 'test_helper'

module Workarea
  class AddMultipleCartItems
    class ItemTest < TestCase
      setup :products

      def products
        @products ||= [
          create_product(
            id: 'PROD1',
            variants: [{ sku: 'SKU1', regular: 5.00 }]
          ),
          create_product(
            id: 'PROD2',
            variants: [{ sku: 'SKU2', regular: 10.00 }]
          )
        ]
      end

      def test_save
        order = create_order
        params = { sku: 'sku2', quantity: 1 }
        item = AddMultipleCartItems::Item.new(order, params)

        assert(item.valid?)
        assert(item.save)
        assert(item.persisted?)

        item = item.item
        assert(item.persisted?)
        assert_equal('PROD2', item.product_id)
        assert_equal('SKU2', item.sku)
        assert_equal(1, item.quantity)

        order.reload
        assert_equal(1, order.items.count)

        params = { sku: 'SKU3', quantity: 2 }
        item = AddMultipleCartItems::Item.new(order, params)

        refute(item.save)
        refute(item.persisted?)
        refute(item.item.present?)

        assert_equal(
          t('workarea.add_multiple_cart_items.errors.missing_product'),
          item.errors.full_messages.first
        )

        order.reload
        assert_equal(1, order.items.count)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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