Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Dec 20, 2024
1 parent e4a1d20 commit 02a9d1b
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'test_plugin_helper'

module InsightsCloud
module Api
class InsightsAdvisorControllerTest < ActionController::TestCase
tests ::Api::V2::InsightsAdvisor::InsightsAdvisorController

setup do
@test_org = FactoryBot.create(:organization)
end

test 'shows all hosts with no search param' do
get :host_details, params: { organization_id: @test_org.id }

assert_response :success
assert_template 'api/v2/insights_advisor/host_details'
assert_equal @test_org.hosts.count, assigns(:hosts).count
end

test 'shows hosts with search param' do
search = 'test'
get :host_details, params: { organization_id: @test_org.id, search: search }

assert_response :success
assert_template 'api/v2/insights_advisor/host_details'
assert_equal @test_org.hosts.where('name LIKE ?', "%#{search}%").count, assigns(:hosts).count
refute_equal @test_org.hosts.count, assigns(:hosts).count
end

test 'fails without org id' do
assert_raises ActiveRecord::RecordNotFound do
get :host_details
end
end
end
end
end

0 comments on commit 02a9d1b

Please sign in to comment.