Sha256: 1d022abe1dbb3a4d03eb0d3279bc3d155205104b19a85385403a28810c44d3ad

Contents?: true

Size: 1.38 KB

Versions: 27

Compression:

Stored size: 1.38 KB

Contents

require 'test_helper'

module Workarea
  class Fulfillment
    class SkuTest < TestCase
      def test_validation
        sku = Sku.new(id: 'SKU1', policy: 'shipping')
        assert(sku.valid?)

        sku.policy = 'download'
        refute(sku.valid?)
        assert(sku.errors['file'].present?)

        sku.file = product_image_file
        assert(sku.valid?)
      end

      def test_find_or_initialize_all
        create_fulfillment_sku(id: 'sku1')
        skus = Sku.find_or_initialize_all(%w(sku1 sku2))

        assert_equal(2, skus.size)
        assert(skus.first.persisted?)
        refute(skus.second.persisted?)
      end

      def test_process!
        order = Order.new
        item = order.items.build(sku: 'SKU1')

        sku = Sku.new(id: 'SKU1', policy: 'shipping')
        assert_nil(sku.process!(order_item: item))

        sku = Sku.new(id: 'SKU1', policy: 'foobar')
        assert_raises(Sku::InvalidPolicy) { sku.process!(order_item: item) }

        sku = Sku.new(id: 'SKU1', policy: 'download')
        sku.process!(order_item: item)
        assert_equal(1, Fulfillment::Token.count)
      end

      def test_downloadable?
        sku = Sku.new(id: 'SKU1', policy: 'shipping')
        refute(sku.downloadable?)

        sku.policy = 'download'
        refute(sku.downloadable?)

        sku.file = product_image_file
        assert(sku.downloadable?)
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.26 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.25 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.23 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.22 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.21 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.20 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.19 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.18 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.17 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.16 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.15 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.14 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.13 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.12 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.11 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.10 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.9 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.8 test/models/workarea/fulfillment/sku_test.rb
workarea-core-3.5.7 test/models/workarea/fulfillment/sku_test.rb