Sha256: 8604e48bbbe2d839382863d4c8b47f21e99199b5b7d06bd5944fcc708ed3674b

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

require 'test_helper'

module Workarea
  module Api
    module Admin
      class ProductsIntegrationTest < IntegrationTest
        include Workarea::Admin::IntegrationTest

        setup :set_sample_attributes

        def set_sample_attributes
          @sample_attributes = create_product
                                .as_json
                                .except('_id', 'slug', 'last_indexed_at')
        end

        def test_lists_products
          products = [create_product, create_product]
          get admin_api.products_path
          result = JSON.parse(response.body)['products']

          assert_equal(3, result.length)
          assert_equal(products.second, Catalog::Product.new(result.first))
          assert_equal(products.first, Catalog::Product.new(result.second))
        end

        def test_creates_products
          assert_difference 'Catalog::Product.count', 1 do
            post admin_api.products_path, params: { product: @sample_attributes }
          end
        end

        def test_shows_products
          product = create_product
          get admin_api.product_path(product.id)
          result = JSON.parse(response.body)['product']
          assert_equal(product, Catalog::Product.new(result))
        end

        def test_updates_products
          product = create_product
          patch admin_api.product_path(product.id), params: { product: { name: 'foo' } }

          product.reload
          assert_equal('foo', product.name)
        end

        def test_bulk_upserts_products
          data = [@sample_attributes] * 10

          assert_difference 'Catalog::Product.count', 10 do
            patch admin_api.bulk_products_path, params: { products: data }
          end
        end

        def test_destroys_products
          product = create_product

          assert_difference 'Catalog::Product.count', -1 do
            delete admin_api.product_path(product.id)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
workarea-api-4.4.7 admin/test/integration/workarea/api/admin/products_integration_test.rb
workarea-api-admin-4.4.7 test/integration/workarea/api/admin/products_integration_test.rb
workarea-api-4.4.6 admin/test/integration/workarea/api/admin/products_integration_test.rb
workarea-api-admin-4.4.6 test/integration/workarea/api/admin/products_integration_test.rb