Skip to content
Snippets Groups Projects
Forked from PortalMEC / portalmec
1435 commits behind the upstream repository.
search_controller_test.rb 858 B
require 'test_helper'

class V1::SearchControllerTest < ActionController::TestCase
  tests V1::SearchController

  setup do
    SearchService::SEARCH_CLASSES.each {|search_class| reindex search_class.constantize}
    auth_application
  end

  test 'should search return :ok' do
    SearchService::SEARCH_CLASSES.each do |search_class|
      get :index, search: {search_class: search_class}
      assert_response :ok
    end
  end

  test 'should search with invalid class and return :bad_request' do
    get :index, search: {search_class: 'invalid'}
    assert_response :bad_request
  end

  test 'should autocomplete with invalid class and return :bad_request' do
    get :autocomplete, search: {search_class: 'invalid'}
    assert_response :bad_request
  end

  private

  def reindex(klass)
    klass.reindex
    klass.searchkick_index.refresh
  end

end