|
| 1 | +require 'test_plugin_helper' |
| 2 | + |
| 3 | +module InsightsCloud |
| 4 | + module Api |
| 5 | + class InsightsAdvisorControllerTest < ActionController::TestCase |
| 6 | + tests ::Api::V2::InsightsAdvisor::InsightsAdvisorController |
| 7 | + |
| 8 | + setup do |
| 9 | + @test_org = FactoryBot.create(:organization) |
| 10 | + @host1 = FactoryBot.create(:host, :with_insights_hits, organization: @test_org, hostname: 'insightshost1') |
| 11 | + @host2 = FactoryBot.create(:host, :with_insights_hits, organization: @test_org, hostname: 'insightshost2') |
| 12 | + @host3 = FactoryBot.create(:host, organization: @test_org) |
| 13 | + end |
| 14 | + |
| 15 | + test 'shows all hosts with no search param' do |
| 16 | + get :host_details, params: { organization_id: @test_org.id } |
| 17 | + |
| 18 | + assert_response :success |
| 19 | + assert_template 'api/v2/insights_advisor/host_details' |
| 20 | + assert_equal @test_org.hosts.count, assigns(:hosts).count |
| 21 | + end |
| 22 | + |
| 23 | + test 'shows hosts with search param' do |
| 24 | + search = @host1.name[0..4] |
| 25 | + get :host_details, params: { organization_id: @test_org.id, search: search } |
| 26 | + assert_response :success |
| 27 | + assert_template 'api/v2/insights_advisor/host_details' |
| 28 | + assert_equal @test_org.hosts.where('name LIKE ?', "%#{search}%").count, assigns(:hosts).count |
| 29 | + refute_equal @test_org.hosts.count, assigns(:hosts).count |
| 30 | + end |
| 31 | + |
| 32 | + test 'fails without org id' do |
| 33 | + response = get :host_details |
| 34 | + |
| 35 | + assert_includes response.body, 'Organization not found' |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | +end |
0 commit comments