@@ -867,6 +867,46 @@ describe('S3Adapter tests', () => {
867
867
expect ( commandArg ) . toBeInstanceOf ( PutObjectCommand ) ;
868
868
expect ( commandArg . input . ACL ) . toBeUndefined ( ) ;
869
869
} ) ;
870
+
871
+ it ( 'should return url when config is provided' , async ( ) => {
872
+ const options = {
873
+ bucket : 'bucket-1' ,
874
+ presignedUrl : true
875
+ } ;
876
+ const s3 = new S3Adapter ( options ) ;
877
+ s3 . _s3Client = s3ClientMock ;
878
+
879
+ // Mock getFileLocation to return a presigned URL
880
+ spyOn ( s3 , 'getFileLocation' ) . and . returnValue ( Promise . resolve ( 'https://presigned-url.com/file.txt' ) ) ;
881
+
882
+ const result = await s3 . createFile (
883
+ 'file.txt' ,
884
+ 'hello world' ,
885
+ 'text/utf8' ,
886
+ { } ,
887
+ { mount : 'http://example.com' , applicationId : 'test123' }
888
+ ) ;
889
+
890
+ expect ( result . url ) . toBe ( 'https://presigned-url.com/file.txt' ) ;
891
+ expect ( result . location ) . toBeDefined ( ) ;
892
+ expect ( result . name ) . toBe ( 'file.txt' ) ;
893
+ expect ( result . s3_response ) . toBeDefined ( ) ;
894
+ } ) ;
895
+
896
+ it ( 'should handle generateKey function errors' , async ( ) => {
897
+ const options = {
898
+ bucket : 'bucket-1' ,
899
+ generateKey : ( ) => {
900
+ throw new Error ( 'Generate key failed' ) ;
901
+ }
902
+ } ;
903
+ const s3 = new S3Adapter ( options ) ;
904
+ s3 . _s3Client = s3ClientMock ;
905
+
906
+ await expectAsync (
907
+ s3 . createFile ( 'file.txt' , 'hello world' , 'text/utf8' , { } )
908
+ ) . toBeRejectedWithError ( 'Generate key failed' ) ;
909
+ } ) ;
870
910
} ) ;
871
911
872
912
describe ( 'handleFileStream' , ( ) => {
0 commit comments