@@ -509,154 +509,6 @@ describe('headObject', () => {
509509 } ) ;
510510} ) ;
511511
512- describe ( 'listAllObjects' , ( ) => {
513- const listObjectsV2Mock = jest . spyOn ( service , 'listObjectsV2' ) ;
514-
515- beforeEach ( ( ) => {
516- listObjectsV2Mock . mockReset ( ) ;
517- } ) ;
518-
519- afterAll ( ( ) => {
520- listObjectsV2Mock . mockRestore ( ) ;
521- } ) ;
522-
523- it ( 'should call listObjectsV2 at least once and return an empty array' , async ( ) => {
524- listObjectsV2Mock . mockResolvedValue ( { IsTruncated : false } ) ;
525-
526- const result = await service . listAllObjects ( ) ;
527-
528- expect ( result ) . toBeTruthy ( ) ;
529- expect ( Array . isArray ( result ) ) . toBeTruthy ( ) ;
530- expect ( result ) . toHaveLength ( 0 ) ;
531- expect ( utils . getBucket ) . toHaveBeenCalledTimes ( 1 ) ;
532- expect ( utils . isAtPath ) . toHaveBeenCalledTimes ( 0 ) ;
533- expect ( listObjectsV2Mock ) . toHaveBeenCalledTimes ( 1 ) ;
534- expect ( listObjectsV2Mock ) . toHaveBeenCalledWith ( expect . objectContaining ( {
535- filePath : key
536- } ) ) ;
537- } ) ;
538-
539- it ( 'should call listObjectsV2 at least once and return an empty array of objects' , async ( ) => {
540- listObjectsV2Mock . mockResolvedValue ( { Contents : [ ] , IsTruncated : false } ) ;
541-
542- const result = await service . listAllObjects ( ) ;
543-
544- expect ( result ) . toBeTruthy ( ) ;
545- expect ( Array . isArray ( result ) ) . toBeTruthy ( ) ;
546- expect ( result ) . toHaveLength ( 0 ) ;
547- expect ( utils . getBucket ) . toHaveBeenCalledTimes ( 1 ) ;
548- expect ( utils . isAtPath ) . toHaveBeenCalledTimes ( 0 ) ;
549- expect ( listObjectsV2Mock ) . toHaveBeenCalledTimes ( 1 ) ;
550- expect ( listObjectsV2Mock ) . toHaveBeenCalledWith ( expect . objectContaining ( {
551- filePath : key
552- } ) ) ;
553- } ) ;
554-
555- it ( 'should call listObjectsV2 multiple times and return an array of precise path objects' , async ( ) => {
556- const continueToken = 'token' ;
557- listObjectsV2Mock . mockResolvedValueOnce ( {
558- Contents : [ { Key : 'filePath/foo' } ] ,
559- IsTruncated : true ,
560- NextContinuationToken : continueToken
561- } ) ;
562- listObjectsV2Mock . mockResolvedValueOnce ( {
563- Contents : [ { Key : 'filePath/bar' } ] ,
564- IsTruncated : false
565- } ) ;
566-
567- const result = await service . listAllObjects ( ) ;
568-
569- expect ( result ) . toBeTruthy ( ) ;
570- expect ( Array . isArray ( result ) ) . toBeTruthy ( ) ;
571- expect ( result ) . toHaveLength ( 2 ) ;
572- expect ( result ) . toEqual ( expect . arrayContaining ( [
573- { Key : 'filePath/foo' } ,
574- { Key : 'filePath/bar' }
575- ] ) ) ;
576- expect ( utils . getBucket ) . toHaveBeenCalledTimes ( 1 ) ;
577- expect ( utils . isAtPath ) . toHaveBeenCalledTimes ( 2 ) ;
578- expect ( listObjectsV2Mock ) . toHaveBeenCalledTimes ( 2 ) ;
579- expect ( listObjectsV2Mock ) . toHaveBeenNthCalledWith ( 1 , expect . objectContaining ( {
580- filePath : key
581- } ) ) ;
582- expect ( listObjectsV2Mock ) . toHaveBeenNthCalledWith ( 2 , expect . objectContaining ( {
583- filePath : key ,
584- continuationToken : continueToken
585- } ) ) ;
586- } ) ;
587-
588- it ( 'should call listObjectsV2 multiple times and return an array of all path objects' , async ( ) => {
589- const continueToken = 'token' ;
590- listObjectsV2Mock . mockResolvedValueOnce ( {
591- Contents : [ { Key : 'filePath/test/foo' } ] ,
592- IsTruncated : true ,
593- NextContinuationToken : continueToken
594- } ) ;
595- listObjectsV2Mock . mockResolvedValueOnce ( {
596- Contents : [ { Key : 'filePath/test/bar' } ] ,
597- IsTruncated : false
598- } ) ;
599-
600- const result = await service . listAllObjects ( { precisePath : false } ) ;
601-
602- expect ( result ) . toBeTruthy ( ) ;
603- expect ( Array . isArray ( result ) ) . toBeTruthy ( ) ;
604- expect ( result ) . toHaveLength ( 2 ) ;
605- expect ( result ) . toEqual ( expect . arrayContaining ( [
606- { Key : 'filePath/test/foo' } ,
607- { Key : 'filePath/test/bar' }
608- ] ) ) ;
609- expect ( utils . getBucket ) . toHaveBeenCalledTimes ( 1 ) ;
610- expect ( utils . isAtPath ) . toHaveBeenCalledTimes ( 0 ) ;
611- expect ( listObjectsV2Mock ) . toHaveBeenCalledTimes ( 2 ) ;
612- expect ( listObjectsV2Mock ) . toHaveBeenNthCalledWith ( 1 , expect . objectContaining ( {
613- filePath : key
614- } ) ) ;
615- expect ( listObjectsV2Mock ) . toHaveBeenNthCalledWith ( 2 , expect . objectContaining ( {
616- filePath : key ,
617- continuationToken : continueToken
618- } ) ) ;
619- } ) ;
620-
621- it (
622- 'should call listObjectsV2 multiple times with the right bucketId and filePath, returning an array of objects' ,
623- async ( ) => {
624- const continueToken = 'token' ;
625- const customPath = 'filePath/test' ;
626- listObjectsV2Mock . mockResolvedValueOnce ( {
627- Contents : [ { Key : 'filePath/test/foo' } ] ,
628- IsTruncated : true ,
629- NextContinuationToken : continueToken
630- } ) ;
631- listObjectsV2Mock . mockResolvedValueOnce ( {
632- Contents : [ { Key : 'filePath/test/bar' } ] ,
633- IsTruncated : false
634- } ) ;
635-
636- const result = await service . listAllObjects ( { filePath : customPath , bucketId : bucket } ) ;
637-
638- expect ( result ) . toBeTruthy ( ) ;
639- expect ( Array . isArray ( result ) ) . toBeTruthy ( ) ;
640- expect ( result ) . toHaveLength ( 2 ) ;
641- expect ( result ) . toEqual ( expect . arrayContaining ( [
642- { Key : 'filePath/test/foo' } ,
643- { Key : 'filePath/test/bar' }
644- ] ) ) ;
645- expect ( utils . getBucket ) . toHaveBeenCalledTimes ( 0 ) ;
646- expect ( utils . isAtPath ) . toHaveBeenCalledTimes ( 2 ) ;
647- expect ( listObjectsV2Mock ) . toHaveBeenCalledTimes ( 2 ) ;
648- expect ( listObjectsV2Mock ) . toHaveBeenNthCalledWith ( 1 , expect . objectContaining ( {
649- filePath : customPath ,
650- bucketId : bucket
651- } ) ) ;
652- expect ( listObjectsV2Mock ) . toHaveBeenNthCalledWith ( 2 , expect . objectContaining ( {
653- filePath : customPath ,
654- continuationToken : continueToken ,
655- bucketId : bucket
656- } ) ) ;
657- }
658- ) ;
659- } ) ;
660512
661513describe ( 'listAllObjectVersions' , ( ) => {
662514 const listObjectVersionMock = jest . spyOn ( service , 'listObjectVersion' ) ;
0 commit comments