@@ -12,27 +12,19 @@ class InsightsAdvisorControllerTest < ActionController::TestCase
12
12
@host3 = FactoryBot . create ( :host , organization : @test_org )
13
13
end
14
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 }
15
+ test 'shows hosts with uuids' do
16
+ uuids = [ @host1 . insights . uuid , @host2 . insights . uuid ]
17
+ get :host_details , params : { organization_id : @test_org . id , host_uuids : uuids }
26
18
assert_response :success
27
19
assert_template 'api/v2/insights_advisor/host_details'
28
- assert_equal @test_org . hosts . where ( 'name LIKE ?' , "% #{ search } %" ) . count , assigns ( :hosts ) . count
20
+ assert_equal @test_org . hosts . joins ( :insights ) . where ( :insights => { :uuid => uuids } ) . count , assigns ( :hosts ) . count
29
21
refute_equal @test_org . hosts . count , assigns ( :hosts ) . count
30
22
end
31
23
32
- test 'fails without org id ' do
33
- response = get :host_details
34
-
35
- assert_includes response . body , 'Organization not found'
24
+ test 'shows error when no hosts found ' do
25
+ get :host_details , params : { organization_id : @test_org . id , host_uuids : [ 'nonexistentuuid' ] }
26
+ assert_response :not_found
27
+ assert_equal 'No hosts found for the given UUIDs' , JSON . parse ( response . body ) [ 'error' ]
36
28
end
37
29
end
38
30
end
0 commit comments