Skip to content

Commit

Permalink
chore: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Kumar committed Sep 20, 2024
1 parent fb5e05c commit 0d3ca41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions packages/storage/__tests__/providers/s3/utils/md5.native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ describe('calculateContentMd5 (native)', () => {
mockMd5.mockReset();
});

it('calculates MD5 for content type: string', async () => {
await calculateContentMd5(stringContent);
const [mockMd5Instance] = mockMd5.mock.instances;
expect(mockMd5Instance.update.mock.calls[0][0]).toBe(stringContent);
expect(mockToBase64).toHaveBeenCalled();
});

it.each([
{ type: 'string', content: stringContent },
{ type: 'ArrayBuffer view', content: new Uint8Array() },
{ type: 'ArrayBuffer', content: new ArrayBuffer(8) },
{ type: 'Blob', content: new Blob([stringContent]) },
])('calculates MD5 for content type: $type', async ({ content }) => {
await calculateContentMd5(content);
const [mockMd5Instance] = mockMd5.mock.instances;
expect(mockMd5Instance.update.mock.calls[0][0]).toBe(content);
expect(mockToBase64).toHaveBeenCalled();
});

it('calculates MD5 for content type: blob', async () => {
Object.defineProperty(global, 'FileReader', {
writable: true,
value: jest.fn(() => mockSuccessfulFileReader),
});
await calculateContentMd5(content);
await calculateContentMd5(new Blob([stringContent]));
const [mockMd5Instance] = mockMd5.mock.instances;
expect(mockMd5Instance.update.mock.calls[0][0]).toBe(fileReaderResult);
expect(mockSuccessfulFileReader.readAsArrayBuffer).toHaveBeenCalled();
Expand Down
18 changes: 9 additions & 9 deletions packages/storage/__tests__/providers/s3/utils/md5.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ describe('calculateContentMd5', () => {
mockMd5.mockReset();
});

it('calculates MD5 for content type: string', async () => {
await calculateContentMd5(stringContent);
const [mockMd5Instance] = mockMd5.mock.instances;
expect(mockMd5Instance.update.mock.calls[0][0]).toBe(stringContent);
expect(mockToBase64).toHaveBeenCalled();
});

it.each([
{ type: 'string', content: stringContent },
{ type: 'ArrayBuffer view', content: new Uint8Array() },
{ type: 'ArrayBuffer', content: new ArrayBuffer(8) },
{ type: 'Blob', content: new Blob([stringContent]) },
])('calculates MD5 for content type: $type', async ({ content }) => {
await calculateContentMd5(content);
const [mockMd5Instance] = mockMd5.mock.instances;
expect(mockMd5Instance.update.mock.calls[0][0]).toBe(content);
expect(mockToBase64).toHaveBeenCalled();
});

it('calculates MD5 for content type: blob', async () => {
Object.defineProperty(global, 'FileReader', {
writable: true,
value: jest.fn(() => mockSuccessfulFileReader),
});
await calculateContentMd5(content);
await calculateContentMd5(new Blob([stringContent]));
const [mockMd5Instance] = mockMd5.mock.instances;
expect(mockMd5Instance.update.mock.calls[0][0]).toBe(fileReaderResult);
expect(mockSuccessfulFileReader.readAsArrayBuffer).toHaveBeenCalled();
Expand Down

0 comments on commit 0d3ca41

Please sign in to comment.