@@ -446,6 +446,62 @@ describe("GET /records", () => {
446446 await agent . get ( "/api/v2/records?recordIds[]=14" ) . expect ( 500 ) ;
447447 expect ( logger . error ) . toHaveBeenCalledWith ( testError ) ;
448448 } ) ;
449+ test ( "expect to return records filtered by archiveId" , async ( ) => {
450+ const response = await agent
451+ . get ( "/api/v2/records?archiveId=1" )
452+ . expect ( 200 ) ;
453+ const { body : records } = response as { body : ArchiveRecord [ ] } ;
454+ const recordIds = records . map ( ( record ) => record . recordId ) ;
455+ expect ( recordIds ) . toContain ( "1" ) ;
456+ expect ( recordIds ) . toContain ( "2" ) ;
457+ expect ( recordIds ) . toContain ( "3" ) ;
458+ expect ( recordIds ) . toContain ( "8" ) ;
459+ expect ( recordIds ) . toContain ( "9" ) ;
460+ expect ( recordIds ) . not . toContain ( "4" ) ;
461+ expect ( recordIds ) . not . toContain ( "5" ) ;
462+ expect ( recordIds ) . not . toContain ( "12" ) ;
463+ expect ( recordIds ) . not . toContain ( "14" ) ;
464+ } ) ;
465+ test ( "expect archiveId and recordIds to act as an AND filter" , async ( ) => {
466+ const response = await agent
467+ . get ( "/api/v2/records?archiveId=1&recordIds[]=1" )
468+ . expect ( 200 ) ;
469+ const { body : records } = response as { body : ArchiveRecord [ ] } ;
470+ expect ( records . length ) . toEqual ( 1 ) ;
471+ expect ( records [ 0 ] ?. recordId ) . toEqual ( "1" ) ;
472+ } ) ;
473+ test ( "expect archiveId with no matching records to return empty array" , async ( ) => {
474+ const response = await agent
475+ . get ( "/api/v2/records?archiveId=9999" )
476+ . expect ( 200 ) ;
477+ const { body : records } = response as { body : ArchiveRecord [ ] } ;
478+ expect ( records . length ) . toEqual ( 0 ) ;
479+ } ) ;
480+ test ( "expect archiveId for non-owned archive to return only public records" , async ( ) => {
481+ const response = await agent
482+ . get ( "/api/v2/records?archiveId=2" )
483+ . expect ( 200 ) ;
484+ const { body : records } = response as { body : ArchiveRecord [ ] } ;
485+ const recordIds = records . map ( ( record ) => record . recordId ) ;
486+ expect ( recordIds ) . toContain ( "5" ) ;
487+ expect ( recordIds ) . toContain ( "6" ) ;
488+ expect ( recordIds ) . not . toContain ( "7" ) ;
489+ } ) ;
490+ test ( "expect archiveId query without recordIds still requires archiveId" , async ( ) => {
491+ await agent . get ( "/api/v2/records" ) . expect ( 400 ) ;
492+ } ) ;
493+ test ( "expect return records by archiveId for a public record when not logged in" , async ( ) => {
494+ mockExtractUserEmailFromAuthToken ( ) ;
495+ const response = await agent
496+ . get ( "/api/v2/records?archiveId=1" )
497+ . expect ( 200 ) ;
498+ const { body : records } = response as { body : ArchiveRecord [ ] } ;
499+ const recordIds = records . map ( ( record ) => record . recordId ) ;
500+ expect ( recordIds ) . toContain ( "1" ) ;
501+ expect ( recordIds ) . toContain ( "8" ) ;
502+ expect ( recordIds ) . not . toContain ( "2" ) ;
503+ expect ( recordIds ) . not . toContain ( "3" ) ;
504+ } ) ;
449505} ) ;
450506
451507describe ( "PATCH /records" , ( ) => {
0 commit comments