Skip to content

Commit 84e11a5

Browse files
committed
Add tests for url when config is provided and error on generatekey
1 parent 9d760be commit 84e11a5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

spec/test.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,46 @@ describe('S3Adapter tests', () => {
867867
expect(commandArg).toBeInstanceOf(PutObjectCommand);
868868
expect(commandArg.input.ACL).toBeUndefined();
869869
});
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+
});
870910
});
871911

872912
describe('handleFileStream', () => {

0 commit comments

Comments
 (0)