Sha256: 49548a9cad65a8b16df066e42d62d2f02146df680340dbdb19106f3d1c361d6f

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 CategoriesIntegrationTest < IntegrationTest
        include Workarea::Admin::IntegrationTest

        setup :set_sample_attributes

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

        def test_lists_categories
          categories = [create_category, create_category]
          get admin_api.categories_path
          result = JSON.parse(response.body)['categories']

          assert_equal(3, result.length)
          assert_equal(categories.second, Catalog::Category.new(result.first))
          assert_equal(categories.first, Catalog::Category.new(result.second))
        end

        def test_creates_categories
          data = @sample_attributes
          assert_difference 'Catalog::Category.count', 1 do
            post admin_api.categories_path, params: { category: data }
          end
        end

        def test_shows_categories
          category = create_category
          get admin_api.category_path(category.id)
          result = JSON.parse(response.body)['category']
          assert_equal(category, Catalog::Category.new(result))
        end

        def test_updates_categories
          category = create_category
          patch admin_api.category_path(category.id), params: { category: { name: 'foo' } }

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

        def test_bulk_upserts_categories
          data = [@sample_attributes] * 10
          assert_difference 'Catalog::Category.count', 10 do
            patch admin_api.bulk_categories_path, params: { categories: data }
          end
        end

        def test_destroys_categories
          category = create_category

          assert_difference 'Catalog::Category.count', -1 do
            delete admin_api.category_path(category.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/categories_integration_test.rb
workarea-api-admin-4.4.7 test/integration/workarea/api/admin/categories_integration_test.rb
workarea-api-4.4.6 admin/test/integration/workarea/api/admin/categories_integration_test.rb
workarea-api-admin-4.4.6 test/integration/workarea/api/admin/categories_integration_test.rb