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.25 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.24 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.23 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.22 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.21 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.20 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.19 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.18 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.17 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.16 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.15 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.14 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.13 test/queries/workarea/order_item_details_test.rb
workarea-core-3.4.12 test/queries/workarea/order_item_details_test.rb