Sha256: f446c69268e861513b4db00e1312b72832efeb41a4ce7048979ba3e15821b747

Contents?: true

Size: 1.6 KB

Versions: 62

Compression:

Stored size: 1.6 KB

Contents

require 'test_helper'

module Workarea
  module Inventory
    module Policies
      class AllowBackorderTest < TestCase
        def test_available_to_sell
          sku = create_inventory(available: 5, reserve: 3)

          policy = AllowBackorder.new(sku)
          assert_equal(2, policy.available_to_sell)

          sku.update_attributes(backordered: 5)
          assert_equal(7, policy.available_to_sell)

          sku.update_attributes(available: 1, backordered: 2)
          assert_equal(0, policy.available_to_sell)
        end

        def test_purchase
          sku = create_inventory(
            id: 'SKU1',
            policy: 'allow_backorder',
            available: 5,
            backordered: 3
          )

          policy = AllowBackorder.new(sku)
          policy.purchase(3)

          sku.reload
          assert_equal(2, sku.available)
          assert_equal(3, sku.backordered)


          sku = create_inventory(
            id: 'SKU2',
            policy: 'allow_backorder',
            available: 5,
            backordered: 3
          )

          policy = AllowBackorder.new(sku)
          policy.purchase(7)

          sku.reload

          assert_equal(0, sku.available)
          assert_equal(1, sku.backordered)


          sku = create_inventory(
            id: 'SKU3',
            policy: 'allow_backorder',
            available: 0,
            backordered: 3
          )

          policy = AllowBackorder.new(sku)
          policy.purchase(2)

          sku.reload

          assert_equal(0, sku.available)
          assert_equal(1, sku.backordered)
        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/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.26 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.45 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.25 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.23 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.44 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.22 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.43 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.21 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.42 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.20 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.41 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.19 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.40 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.18 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.39 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.17 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.38 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.16 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.37 test/models/workarea/inventory/policies/allow_backorder_test.rb