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 9288434
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'test_plugin_helper'

module InsightsCloud::Api

Check failure on line 3 in test/controllers/insights_cloud/api/insights_advisor_controller_test.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Style/ClassAndModuleChildren: Use nested module/class definitions instead of compact style.
class CloudRequestControllerTest < ActionController::TestCase
tests Api::V2::RhCloud::CloudRequestController

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

test 'shows all hosts with no search param' do

Check failure on line 12 in test/controllers/insights_cloud/api/insights_advisor_controller_test.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/TrailingWhitespace: Trailing whitespace detected.
response = get :host_details, params: { organization_id: @test_org.id }

Check failure on line 13 in test/controllers/insights_cloud/api/insights_advisor_controller_test.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Lint/UselessAssignment: Useless assignment to variable - `response`.

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'
response = get :host_details, params: { organization_id: @test_org.id, search: search }

Check failure on line 22 in test/controllers/insights_cloud/api/insights_advisor_controller_test.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Lint/UselessAssignment: Useless assignment to variable - `response`.

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

Check failure on line 36 in test/controllers/insights_cloud/api/insights_advisor_controller_test.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/TrailingEmptyLines: Final newline missing.

0 comments on commit 9288434

Please sign in to comment.