44
55module Api
66 module V2
7+ # rubocop:disable Metrics/ClassLength
78 class PreupgradeReportsControllerTest < ActionController ::TestCase
89 setup do
910 @host = FactoryBot . create ( :host )
@@ -22,9 +23,11 @@ class PreupgradeReportsControllerTest < ActionController::TestCase
2223 get :show , params : { id : @report . id }
2324 assert_response :success
2425
25- response = JSON . parse ( @response . body )
26- assert_equal response [ 'id' ] , @report . id
27- assert_not_empty response [ 'preupgrade_report_entries' ]
26+ body = JSON . parse ( @response . body )
27+ assert_equal @report . id , body [ 'id' ]
28+ assert_not_empty body [ 'results' ]
29+ assert_not_nil body [ 'total' ]
30+ assert_not_nil body [ 'subtotal' ]
2831 end
2932
3033 test 'should get :job_invocation' do
@@ -96,7 +99,7 @@ class PreupgradeReportsControllerTest < ActionController::TestCase
9699 assert_includes JSON . parse ( @response . body ) [ 'error' ] [ 'missing_permissions' ] , 'view_hosts'
97100 end
98101
99- test 'should not get :job_invocation ' do
102+ test 'should not get :show ' do
100103 get :show , params : { id : @report . id } , session : set_session_user ( @user )
101104 assert_response :forbidden
102105 assert_includes JSON . parse ( @response . body ) [ 'error' ] [ 'missing_permissions' ] , 'view_hosts'
@@ -108,6 +111,34 @@ class PreupgradeReportsControllerTest < ActionController::TestCase
108111 assert_includes JSON . parse ( @response . body ) [ 'error' ] [ 'missing_permissions' ] , 'view_hosts'
109112 end
110113 end
114+
115+ test 'should filter entries by search on :show' do
116+ get :show , params : { id : @report . id , search : "title = \" #{ @entry . title } \" " }
117+ assert_response :success
118+ body = JSON . parse ( @response . body )
119+ assert_equal 1 , body [ 'results' ] . length
120+ assert_equal @entry . id , body [ 'results' ] . first [ 'id' ]
121+ end
122+
123+ test 'should sort entries on :show' do
124+ FactoryBot . create ( :preupgrade_report_entry , host : @host , preupgrade_report : @report ,
125+ title : 'Aaa first alphabetically' )
126+ get :show , params : { id : @report . id , order : 'title ASC' }
127+ assert_response :success
128+ titles = JSON . parse ( @response . body ) [ 'results' ] . map { |e | e [ 'title' ] }
129+ assert_equal titles . sort , titles
130+ end
131+
132+ test ':show always returns paginated results with total and subtotal' do
133+ get :show , params : { id : @report . id }
134+ assert_response :success
135+ body = JSON . parse ( @response . body )
136+ assert_not_empty body [ 'results' ]
137+ assert_not_nil body [ 'total' ]
138+ assert_not_nil body [ 'subtotal' ]
139+ assert_equal body [ 'total' ] , body [ 'subtotal' ]
140+ end
111141 end
142+ # rubocop:enable Metrics/ClassLength
112143 end
113144end
0 commit comments