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