Sha256: cf932ec8274613c110273ca598acd449a26c5fa1ca84861917ff6c08243887df

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

require 'test_helper'

module Workarea
  module FlowIo
    class ItemTest < Workarea::TestCase
      def test_to_h
        item = Item.new(product, product.skus.first)

        assert_equal(expected_product_hash, item.to_h.except(:images))
      end

      private

        def product
          @product ||=
            begin
              prod = create_product(
                id: "EEC66E04BC",
                variants: [{
                  sku: 'SKU',
                  regular: 5.00,
                  details: { "Color" => "Red", "Size" => "X-Small" }
                }],
                images: [
                  { image: product_image_file, option: 'blue' },
                  { image: product_image_file, option: 'red' },
                  { image: product_image_file, option: 'Blue' }
                ]
              )

              prod.variants.each do |variant|
                Shipping::Sku.create!(
                  id: variant.sku,
                  weight: 5,
                  dimensions: [1, 2, 3]
                )
              end

              create_category(product_ids: [prod.id])

              prod
            end
        end

        def expected_product_hash
          {
            number: "SKU",
            locale: "en_US",
            name: "Test Product",
            currency: "USD",
            price: 5.0,
            categories: ["Test Category"],
            attributes: {
              "product_id" => "EEC66E04BC",
              "Color" => "Red",
              "Size" => "X-Small",
              "regular_price" => "5.0",
              "fulfillment_method" => "physical"
            },
            dimensions: {
              packing: {
                depth: { value: 1, units: :inches },
                length: { value: 3, units: :inches },
                width: { value: 2, units: :inches },
                weight: { value: 5.0, units: :ounces }
              }
            }
          }
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-flow_io-1.2.1 test/services/workarea/flow_io/item_test.rb