Sha256: 007ef65c7a230edd6d17e8bd6b3208b38b06add647f78893989fc97379bacf7e

Contents?: true

Size: 2 KB

Versions: 31

Compression:

Stored size: 2 KB

Contents

require 'test_helper'

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

      def test_updates_a_product
        product = create_product(variants: [])

        patch admin.catalog_product_path(product),
          params: { product: { name: 'Test Product', active: true } }

        product.reload
        assert_equal('Test Product', product.name)
        assert(product.active)
      end

      def test_returns_a_list_of_filters
        create_product(filters:  { 'Color' => 'Blue' })

        get admin.filters_catalog_products_path(
            format: 'json',
            name: 'Color',
            q: 'B'
          )

        results = JSON.parse(response.body)
        assert_equal(
          [{ 'label' => 'Blue', 'value' => 'Blue' }],
          results['results']
        )
      end

      def test_returns_a_list_of_details
        create_product(details: { color: 'Red' })

        get admin.details_catalog_products_path(
            format: 'json',
            name: 'color',
            q: 'R'
          )

        results = JSON.parse(response.body)

        assert_equal(
          [{ 'label' => 'Red', 'value' => 'Red' }],
          results['results']
        )
      end

      def test_autocompletes_partial_queries_when_xhr
        product = create_product(name: 'Test Product')
        create_top_products(results: [{ product_id: product.id }])

        get admin.catalog_products_path(format: 'json', q: 'tes'), xhr: true

        results = JSON.parse(response.body)
        assert_equal(1, results['results'].length)
        assert(results['results'].first['label'].present?)
        assert_equal(product.id, results['results'].first['value'])
        assert(results['results'].first['top'])
        refute(results['results'].first['trending'])
      end

      def test_destroy
        product = create_product
        delete admin.catalog_product_path(product)
        assert_equal(0, Catalog::Product.count)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
workarea-admin-3.5.9 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.31 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.8 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.30 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.7 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.29 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.6 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.28 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.5 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.27 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.4 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.26 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.3 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.25 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.2 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.24 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.1 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.23 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.4.22 test/integration/workarea/admin/products_integration_test.rb
workarea-admin-3.5.0 test/integration/workarea/admin/products_integration_test.rb