Skip to content

Commit f0ae76e

Browse files
committed
test: add unit test
1 parent 14a23f7 commit f0ae76e

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

packages/storage/__tests__/providers/s3/apis/internal/uploadData/multipartHandlers.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,42 @@ describe('getMultipartUploadHandlers with key', () => {
619619
expect(mockListParts).not.toHaveBeenCalled();
620620
});
621621

622+
it('should omit unserializable option properties when calculating the hash key', async () => {
623+
mockMultipartUploadSuccess();
624+
const serializableOptions = {
625+
useAccelerateEndpoint: true,
626+
bucket: { bucketName: 'bucket', region: 'us-west-2' },
627+
expectedBucketOwner: '123',
628+
contentDisposition: 'attachment',
629+
contentEncoding: 'deflate',
630+
contentType: 'text/html',
631+
customEndpoint: 'abc',
632+
metadata: {},
633+
preventOverwrite: true,
634+
checksumAlgorithm: 'crc-32' as const,
635+
};
636+
const size = 8 * MB;
637+
const { multipartUploadJob } = getMultipartUploadHandlers(
638+
{
639+
key: defaultKey,
640+
data: new ArrayBuffer(size),
641+
options: {
642+
...serializableOptions,
643+
// The following options will be omitted
644+
locationCredentialsProvider: jest.fn(),
645+
onProgress: jest.fn(),
646+
resumableUploadsCache: mockDefaultStorage,
647+
},
648+
},
649+
size,
650+
);
651+
await multipartUploadJob();
652+
expect(mockCalculateContentCRC32).toHaveBeenNthCalledWith(
653+
1,
654+
JSON.stringify(serializableOptions),
655+
);
656+
});
657+
622658
it('should send createMultipartUpload request if the upload task is not cached', async () => {
623659
mockMultipartUploadSuccess();
624660
const size = 8 * MB;
@@ -1451,6 +1487,42 @@ describe('getMultipartUploadHandlers with path', () => {
14511487
expect(mockListParts).not.toHaveBeenCalled();
14521488
});
14531489

1490+
it('should omit unserializable option properties when calculating the hash key', async () => {
1491+
mockMultipartUploadSuccess();
1492+
const serializableOptions = {
1493+
useAccelerateEndpoint: true,
1494+
bucket: { bucketName: 'bucket', region: 'us-west-2' },
1495+
expectedBucketOwner: '123',
1496+
contentDisposition: 'attachment',
1497+
contentEncoding: 'deflate',
1498+
contentType: 'text/html',
1499+
customEndpoint: 'abc',
1500+
metadata: {},
1501+
preventOverwrite: true,
1502+
checksumAlgorithm: 'crc-32' as const,
1503+
};
1504+
const size = 8 * MB;
1505+
const { multipartUploadJob } = getMultipartUploadHandlers(
1506+
{
1507+
path: testPath,
1508+
data: new ArrayBuffer(size),
1509+
options: {
1510+
...serializableOptions,
1511+
// The following options will be omitted
1512+
locationCredentialsProvider: jest.fn(),
1513+
onProgress: jest.fn(),
1514+
resumableUploadsCache: mockDefaultStorage,
1515+
},
1516+
},
1517+
size,
1518+
);
1519+
await multipartUploadJob();
1520+
expect(mockCalculateContentCRC32).toHaveBeenNthCalledWith(
1521+
1,
1522+
JSON.stringify(serializableOptions),
1523+
);
1524+
});
1525+
14541526
it('should send createMultipartUpload request if the upload task is cached but outdated', async () => {
14551527
mockDefaultStorage.getItem.mockResolvedValue(
14561528
JSON.stringify({

0 commit comments

Comments
 (0)