@@ -834,6 +834,46 @@ describe('S3Adapter tests', () => {
834834 expect ( commandArg ) . toBeInstanceOf ( PutObjectCommand ) ;
835835 expect ( commandArg . input . ACL ) . toBeUndefined ( ) ;
836836 } ) ;
837+
838+ it ( 'should return url when config is provided' , async ( ) => {
839+ const options = {
840+ bucket : 'bucket-1' ,
841+ presignedUrl : true
842+ } ;
843+ const s3 = new S3Adapter ( options ) ;
844+ s3 . _s3Client = s3ClientMock ;
845+
846+ // Mock getFileLocation to return a presigned URL
847+ spyOn ( s3 , 'getFileLocation' ) . and . returnValue ( Promise . resolve ( 'https://presigned-url.com/file.txt' ) ) ;
848+
849+ const result = await s3 . createFile (
850+ 'file.txt' ,
851+ 'hello world' ,
852+ 'text/utf8' ,
853+ { } ,
854+ { mount : 'http://example.com' , applicationId : 'test123' }
855+ ) ;
856+
857+ expect ( result . url ) . toBe ( 'https://presigned-url.com/file.txt' ) ;
858+ expect ( result . location ) . toBeDefined ( ) ;
859+ expect ( result . name ) . toBe ( 'file.txt' ) ;
860+ expect ( result . s3_response ) . toBeDefined ( ) ;
861+ } ) ;
862+
863+ it ( 'should handle generateKey function errors' , async ( ) => {
864+ const options = {
865+ bucket : 'bucket-1' ,
866+ generateKey : ( ) => {
867+ throw new Error ( 'Generate key failed' ) ;
868+ }
869+ } ;
870+ const s3 = new S3Adapter ( options ) ;
871+ s3 . _s3Client = s3ClientMock ;
872+
873+ await expectAsync (
874+ s3 . createFile ( 'file.txt' , 'hello world' , 'text/utf8' , { } )
875+ ) . toBeRejectedWithError ( 'Generate key failed' ) ;
876+ } ) ;
837877 } ) ;
838878
839879 describe ( 'handleFileStream' , ( ) => {
0 commit comments