@@ -22,9 +22,11 @@ class PreupgradeReportsControllerTest < ActionController::TestCase
2222 get :show , params : { id : @report . id }
2323 assert_response :success
2424
25- response = JSON . parse ( @response . body )
26- assert_equal response [ 'id' ] , @report . id
27- assert_not_empty response [ 'preupgrade_report_entries' ]
25+ body = JSON . parse ( @response . body )
26+ assert_equal @report . id , body [ 'id' ]
27+ assert_not_empty body [ 'results' ]
28+ assert_not_nil body [ 'total' ]
29+ assert_not_nil body [ 'subtotal' ]
2830 end
2931
3032 test 'should get :job_invocation' do
@@ -96,7 +98,7 @@ class PreupgradeReportsControllerTest < ActionController::TestCase
9698 assert_includes JSON . parse ( @response . body ) [ 'error' ] [ 'missing_permissions' ] , 'view_hosts'
9799 end
98100
99- test 'should not get :job_invocation ' do
101+ test 'should not get :show ' do
100102 get :show , params : { id : @report . id } , session : set_session_user ( @user )
101103 assert_response :forbidden
102104 assert_includes JSON . parse ( @response . body ) [ 'error' ] [ 'missing_permissions' ] , 'view_hosts'
@@ -108,6 +110,33 @@ class PreupgradeReportsControllerTest < ActionController::TestCase
108110 assert_includes JSON . parse ( @response . body ) [ 'error' ] [ 'missing_permissions' ] , 'view_hosts'
109111 end
110112 end
113+
114+ test 'should filter entries by search on :show' do
115+ get :show , params : { id : @report . id , search : "title = \" #{ @entry . title } \" " }
116+ assert_response :success
117+ body = JSON . parse ( @response . body )
118+ assert_equal 1 , body [ 'results' ] . length
119+ assert_equal @entry . id , body [ 'results' ] . first [ 'id' ]
120+ end
121+
122+ test 'should sort entries on :show' do
123+ FactoryBot . create ( :preupgrade_report_entry , host : @host , preupgrade_report : @report ,
124+ title : 'Aaa first alphabetically' )
125+ get :show , params : { id : @report . id , order : 'title ASC' }
126+ assert_response :success
127+ titles = JSON . parse ( @response . body ) [ 'results' ] . map { |e | e [ 'title' ] }
128+ assert_equal titles . sort , titles
129+ end
130+
131+ test ':show always returns paginated results with total and subtotal' do
132+ get :show , params : { id : @report . id }
133+ assert_response :success
134+ body = JSON . parse ( @response . body )
135+ assert_not_empty body [ 'results' ]
136+ assert_not_nil body [ 'total' ]
137+ assert_not_nil body [ 'subtotal' ]
138+ assert_equal body [ 'total' ] , body [ 'subtotal' ]
139+ end
111140 end
112141 end
113142end
0 commit comments