Sha256: af7dbcf0f7e5c61e36e52669efae31119ccd6ef72cb86f5f7416f4a1f4d22196

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require 'test_helper'

module Workarea
  module Storefront
    class BundlesProductViewModelTest < TestCase
      def test_bundled_products
        package_child_1 = create_product(variants: [{ sku: 'SKUC1', regular: 5.00 }])
        package_child_2 = create_product
        package_product = create_product(product_ids: [package_child_1.id, package_child_2.id])

        view_model = ProductViewModel.new(package_product)
        assert_equal(package_child_1.id, view_model.bundled_products[0].id)
        assert_equal(package_child_2.id, view_model.bundled_products[1].id)

        create_inventory(id: 'SKUC1', policy: 'standard', available: 0)

        view_model = ProductViewModel.new(package_product)
        assert_equal(package_child_2.id, view_model.bundled_products[0].id)
        assert_equal(1, view_model.bundled_products.count)

        bad_packaged_product = create_product(product_ids: [package_child_2.id, 'not_an_id'])
        view_model = ProductViewModel.new(bad_packaged_product)
        assert_equal(1, view_model.bundled_products.count)
      end

      def test_purchasable?
        product = create_product
        assert(ProductViewModel.new(product).purchasable?)

        kit = create_product(
          product_ids: [product.id],
          variants: [{
            sku: 'FOO',
            regular: 5.to_m,
            components: [{ product_id: product.id, sku: product.skus.first }]
          }]
        )

        assert(ProductViewModel.new(kit).purchasable?)

        product.update!(purchasable: false)
        refute(ProductViewModel.new(product).purchasable?)
        refute(ProductViewModel.new(kit).purchasable?)

        product.update!(purchasable: true)
        kit.update!(purchasable: false)
        assert(ProductViewModel.new(product).purchasable?)
        refute(ProductViewModel.new(kit).purchasable?)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-product_bundles-1.0.1 test/view_models/workarea/storefront/bundles_product_view_model_test.rb
workarea-product_bundles-1.0.0 test/view_models/workarea/storefront/bundles_product_view_model_test.rb