Sha256: abf3be7ab82c1510fc46bec00677e84ce734e5ce72f86c255f8375f46a9e224f

Contents?: true

Size: 1.17 KB

Versions: 62

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'

module Workarea
  class InventoryAdjustmentTest < TestCase
    setup :set_inventory

    def order
      @order ||= create_order(
        items: [
          { product_id: 'PROD1', sku: 'SKU1', quantity: 1 },
          { product_id: 'PROD1', sku: 'SKU2', quantity: 2 },
          { product_id: 'PROD1', sku: 'SKU3', quantity: 3 }
        ]
      )
    end

    def set_inventory
      create_inventory(id: 'SKU1', available: 100, policy: 'standard')
      create_inventory(id: 'SKU2', available: 1, policy: 'standard')
      create_inventory(id: 'SKU3', available: 0, policy: 'standard')
    end

    def test_adjust
      adjustment = InventoryAdjustment.new(order).tap(&:perform)

      assert_equal(2, order.items.count)
      assert_equal(1, order.items[0].quantity)
      assert_equal(1, order.items[1].quantity)
      assert_nil(order.items.detect { |i| i.sku == 'SKU3' })

      assert_includes(
        adjustment.errors,
        I18n.t('workarea.errors.messages.sku_limited_quantity', quantity: 1, sku: 'SKU2')
      )
      assert_includes(
        adjustment.errors,
        I18n.t('workarea.errors.messages.sku_unavailable', sku: 'SKU3')
      )
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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