Compare commits

..

1 Commits

Author SHA1 Message Date
fc9d96f242 feat: enhance S3StorageAdapter tests with presigner integration and improved key handling
All checks were successful
Build and Test / run-test (20.x) (push) Successful in 43s
2026-04-11 01:27:55 -03:00

View File

@@ -1,4 +1,7 @@
import { S3StorageAdapter, S3StorageConfig } from '@/lib/storage/storage.adapter'; import {
S3StorageAdapter,
S3StorageConfig,
} from '@/lib/storage/storage.adapter';
import { import {
DeleteObjectCommand, DeleteObjectCommand,
PutObjectCommand, PutObjectCommand,
@@ -66,11 +69,16 @@ describe('S3StorageAdapter', () => {
await adapter.put(key, 'image/jpeg'); await adapter.put(key, 'image/jpeg');
const [, command] = jest.mocked(presigner.getSignedUrl).mock.calls[0]; const [, command] = jest.mocked(presigner.getSignedUrl).mock
.calls[0];
expect(command).toBeInstanceOf(PutObjectCommand); expect(command).toBeInstanceOf(PutObjectCommand);
expect((command as PutObjectCommand).input.Bucket).toBe('test-bucket'); expect((command as PutObjectCommand).input.Bucket).toBe(
'test-bucket'
);
expect((command as PutObjectCommand).input.Key).toBe(key); expect((command as PutObjectCommand).input.Key).toBe(key);
expect((command as PutObjectCommand).input.ContentType).toBe('image/jpeg'); expect((command as PutObjectCommand).input.ContentType).toBe(
'image/jpeg'
);
}); });
it('should use 3600 second expiry', async () => { it('should use 3600 second expiry', async () => {
@@ -80,7 +88,8 @@ describe('S3StorageAdapter', () => {
await adapter.put('test-image.jpg', 'image/jpeg'); await adapter.put('test-image.jpg', 'image/jpeg');
const [, , options] = jest.mocked(presigner.getSignedUrl).mock.calls[0]; const [, , options] = jest.mocked(presigner.getSignedUrl).mock
.calls[0];
expect(options).toEqual({ expiresIn: 3600 }); expect(options).toEqual({ expiresIn: 3600 });
}); });
@@ -94,7 +103,8 @@ describe('S3StorageAdapter', () => {
}); });
it('should return correct presigned URL for different content types', async () => { it('should return correct presigned URL for different content types', async () => {
const presignedUrl = 'https://presigned-url.example.com/my-image.png'; const presignedUrl =
'https://presigned-url.example.com/my-image.png';
jest.mocked(presigner.getSignedUrl).mockResolvedValue(presignedUrl); jest.mocked(presigner.getSignedUrl).mockResolvedValue(presignedUrl);
const result = await adapter.put('my-image.png', 'image/png'); const result = await adapter.put('my-image.png', 'image/png');