@@ -304,7 +304,9 @@ export default ({ getService }: FtrProviderContext): void => {
304304 . get ( `${ CASES_URL } /_find?sortOrder=asc&status=open` )
305305 . expect ( 200 ) ;
306306
307- expect ( body . total ) . to . eql ( 2 ) ;
307+ // since we're filtering on status and the collection only has an in-progress case, it should only return the
308+ // individual case that has the open status and no collections
309+ expect ( body . total ) . to . eql ( 1 ) ;
308310 expect ( body . count_closed_cases ) . to . eql ( 1 ) ;
309311 expect ( body . count_open_cases ) . to . eql ( 1 ) ;
310312 expect ( body . count_in_progress_cases ) . to . eql ( 1 ) ;
@@ -353,7 +355,7 @@ export default ({ getService }: FtrProviderContext): void => {
353355 expect ( body . count_in_progress_cases ) . to . eql ( 0 ) ;
354356 } ) ;
355357
356- it ( 'correctly counts stats including a collection without sub cases' , async ( ) => {
358+ it ( 'correctly counts stats including a collection without sub cases when not filtering on status ' , async ( ) => {
357359 // delete the sub case on the collection so that it doesn't have any sub cases
358360 await supertest
359361 . delete ( `${ SUB_CASES_PATCH_DEL_URL } ?ids=["${ collection . newSubCaseInfo . subCases ! [ 0 ] . id } "]` )
@@ -365,11 +367,62 @@ export default ({ getService }: FtrProviderContext): void => {
365367 . get ( `${ CASES_URL } /_find?sortOrder=asc` )
366368 . expect ( 200 ) ;
367369
370+ // it should include the collection without sub cases because we did not pass in a filter on status
371+ expect ( body . total ) . to . eql ( 3 ) ;
372+ expect ( body . count_closed_cases ) . to . eql ( 1 ) ;
373+ expect ( body . count_open_cases ) . to . eql ( 1 ) ;
374+ expect ( body . count_in_progress_cases ) . to . eql ( 0 ) ;
375+ } ) ;
376+
377+ it ( 'correctly counts stats including a collection without sub cases when filtering on tags' , async ( ) => {
378+ // delete the sub case on the collection so that it doesn't have any sub cases
379+ await supertest
380+ . delete ( `${ SUB_CASES_PATCH_DEL_URL } ?ids=["${ collection . newSubCaseInfo . subCases ! [ 0 ] . id } "]` )
381+ . set ( 'kbn-xsrf' , 'true' )
382+ . send ( )
383+ . expect ( 204 ) ;
384+
385+ const { body } : { body : CasesFindResponse } = await supertest
386+ . get ( `${ CASES_URL } /_find?sortOrder=asc&tags=defacement` )
387+ . expect ( 200 ) ;
388+
389+ // it should include the collection without sub cases because we did not pass in a filter on status
368390 expect ( body . total ) . to . eql ( 3 ) ;
369391 expect ( body . count_closed_cases ) . to . eql ( 1 ) ;
370392 expect ( body . count_open_cases ) . to . eql ( 1 ) ;
371393 expect ( body . count_in_progress_cases ) . to . eql ( 0 ) ;
372394 } ) ;
395+
396+ it ( 'does not return collections without sub cases matching the requested status' , async ( ) => {
397+ const { body } : { body : CasesFindResponse } = await supertest
398+ . get ( `${ CASES_URL } /_find?sortOrder=asc&status=closed` )
399+ . expect ( 200 ) ;
400+
401+ // it should not include the collection that has a sub case as in-progress
402+ expect ( body . total ) . to . eql ( 1 ) ;
403+ expect ( body . count_closed_cases ) . to . eql ( 1 ) ;
404+ expect ( body . count_open_cases ) . to . eql ( 1 ) ;
405+ expect ( body . count_in_progress_cases ) . to . eql ( 1 ) ;
406+ } ) ;
407+
408+ it ( 'does not return empty collections when filtering on status' , async ( ) => {
409+ // delete the sub case on the collection so that it doesn't have any sub cases
410+ await supertest
411+ . delete ( `${ SUB_CASES_PATCH_DEL_URL } ?ids=["${ collection . newSubCaseInfo . subCases ! [ 0 ] . id } "]` )
412+ . set ( 'kbn-xsrf' , 'true' )
413+ . send ( )
414+ . expect ( 204 ) ;
415+
416+ const { body } : { body : CasesFindResponse } = await supertest
417+ . get ( `${ CASES_URL } /_find?sortOrder=asc&status=closed` )
418+ . expect ( 200 ) ;
419+
420+ // it should not include the collection that has a sub case as in-progress
421+ expect ( body . total ) . to . eql ( 1 ) ;
422+ expect ( body . count_closed_cases ) . to . eql ( 1 ) ;
423+ expect ( body . count_open_cases ) . to . eql ( 1 ) ;
424+ expect ( body . count_in_progress_cases ) . to . eql ( 0 ) ;
425+ } ) ;
373426 } ) ;
374427
375428 it ( 'unhappy path - 400s when bad query supplied' , async ( ) => {
0 commit comments