Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jan 21, 2025
1 parent 14a23f7 commit f0ae76e
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,42 @@ describe('getMultipartUploadHandlers with key', () => {
expect(mockListParts).not.toHaveBeenCalled();
});

it('should omit unserializable option properties when calculating the hash key', async () => {
mockMultipartUploadSuccess();
const serializableOptions = {
useAccelerateEndpoint: true,
bucket: { bucketName: 'bucket', region: 'us-west-2' },
expectedBucketOwner: '123',
contentDisposition: 'attachment',
contentEncoding: 'deflate',
contentType: 'text/html',
customEndpoint: 'abc',
metadata: {},
preventOverwrite: true,
checksumAlgorithm: 'crc-32' as const,
};
const size = 8 * MB;
const { multipartUploadJob } = getMultipartUploadHandlers(
{
key: defaultKey,
data: new ArrayBuffer(size),
options: {
...serializableOptions,
// The following options will be omitted
locationCredentialsProvider: jest.fn(),
onProgress: jest.fn(),
resumableUploadsCache: mockDefaultStorage,
},
},
size,
);
await multipartUploadJob();
expect(mockCalculateContentCRC32).toHaveBeenNthCalledWith(
1,
JSON.stringify(serializableOptions),
);
});

it('should send createMultipartUpload request if the upload task is not cached', async () => {
mockMultipartUploadSuccess();
const size = 8 * MB;
Expand Down Expand Up @@ -1451,6 +1487,42 @@ describe('getMultipartUploadHandlers with path', () => {
expect(mockListParts).not.toHaveBeenCalled();
});

it('should omit unserializable option properties when calculating the hash key', async () => {
mockMultipartUploadSuccess();
const serializableOptions = {
useAccelerateEndpoint: true,
bucket: { bucketName: 'bucket', region: 'us-west-2' },
expectedBucketOwner: '123',
contentDisposition: 'attachment',
contentEncoding: 'deflate',
contentType: 'text/html',
customEndpoint: 'abc',
metadata: {},
preventOverwrite: true,
checksumAlgorithm: 'crc-32' as const,
};
const size = 8 * MB;
const { multipartUploadJob } = getMultipartUploadHandlers(
{
path: testPath,
data: new ArrayBuffer(size),
options: {
...serializableOptions,
// The following options will be omitted
locationCredentialsProvider: jest.fn(),
onProgress: jest.fn(),
resumableUploadsCache: mockDefaultStorage,
},
},
size,
);
await multipartUploadJob();
expect(mockCalculateContentCRC32).toHaveBeenNthCalledWith(
1,
JSON.stringify(serializableOptions),
);
});

it('should send createMultipartUpload request if the upload task is cached but outdated', async () => {
mockDefaultStorage.getItem.mockResolvedValue(
JSON.stringify({
Expand Down

0 comments on commit f0ae76e

Please # to comment.