Sha256: 8cf8f597fbcc896dca8d6b24ebb6dc46dd2f1858a8d75b779e2903ec48fc0c79

Contents?: true

Size: 1.48 KB

Versions: 34

Compression:

Stored size: 1.48 KB

Contents

require 'test_helper'

module Workarea
  class OrderItemDetailsTest < Workarea::TestCase
    def test_find_bang_without_product
      assert_raises OrderItemDetails::InvalidPurchase do
        OrderItemDetails.find!('SKU1')
      end
    end

    def test_find_without_product
      assert_nil(OrderItemDetails.find('SKU1'))
    end

    def test_to_h
      product = create_product(id: "840B898080", variants: [{ sku: 'SKU', regular: 5.00 }])
      # we lose time precision on created_at/updated_at when storing in the database
      # reload the product to truncate the timestamps
      product.reload
      details = OrderItemDetails.find!('SKU').to_h

      assert_equal("840B898080", details[:product_id])
      assert_equal(product.as_document, details[:product_attributes])
    end

    def test_shared_sku_products
      product = create_product(id: "840B898080", variants: [{ sku: 'SKU', regular: 5.00 }])
      product.reload
      Catalog::Product.create!(id: "840B898081", name: "Product Test", variants: [{ sku: "SKU" }])

      details = OrderItemDetails.find!('SKU', product_id: "840B898080").to_h

      assert_equal("840B898080", details[:product_id])
      assert_equal(product.as_document, details[:product_attributes])

      product = Catalog::Product.find("840B898081")
      details = OrderItemDetails.find!('SKU', product_id: "840B898081").to_h

      assert_equal("840B898081", details[:product_id])
      assert_equal(product.as_document, details[:product_attributes])
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.44 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.43 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.42 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.41 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.40 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.39 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.38 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.37 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.36 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.35 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.34 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.33 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.32 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.31 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.30 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.29 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.28 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.27 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.26 test/queries/workarea/order_item_details_test.rb