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.15 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.36 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.14 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.35 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.13 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.34 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.12 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.33 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.11 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.10 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.32 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.9 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.31 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.8 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.30 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.7 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.29 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.6 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.4.28 test/models/workarea/inventory/policies/allow_backorder_test.rb
workarea-core-3.5.5 test/models/workarea/inventory/policies/allow_backorder_test.rb