Skip to content

Commit

Permalink
fix: more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Sep 13, 2023
1 parent 90fb863 commit 939bf37
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Amplify } from '@aws-amplify/core';
import { getObject } from '../../../../src/providers/s3/utils/client';
import { downloadData } from '../../../../src/providers/s3';
import { createDownloadTask } from '../../../../src/providers/s3/utils';
import { StorageOptions } from '../../../../src/types';
import { DownloadDataOptions } from '../../../../src/providers/s3/types';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('../../../../src/providers/s3/utils');
Expand Down Expand Up @@ -93,10 +93,10 @@ describe('downloadData', () => {
downloadData({
key,
options: {
...(options as StorageOptions),
...options,
useAccelerateEndpoint: true,
onProgress,
},
} as DownloadDataOptions,
});
const job = mockCreateDownloadTask.mock.calls[0][0].job;
await job();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { headObject } from '../../../../src/providers/s3/utils/client';
import { getProperties } from '../../../../src/providers/s3';
import { Credentials } from '@aws-sdk/types';
import { Amplify } from '@aws-amplify/core';
import { StorageOptions } from '../../../../src/types';
import { GetPropertiesOptions } from '../../../../src/providers/s3/types';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('@aws-amplify/core', () => ({
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('getProperties api', () => {
expect(
await getProperties({
key,
options: options as StorageOptions,
options: options as GetPropertiesOptions,
})
).toEqual(expected);
expect(headObject).toBeCalledTimes(1);
Expand Down
6 changes: 3 additions & 3 deletions packages/storage/__tests__/providers/s3/apis/getUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getPresignedGetObjectUrl,
headObject,
} from '../../../../src/providers/s3/utils/client';
import { StorageOptions } from '../../../../src/types';
import { GetUrlOptions } from '../../../../src/providers/s3/types';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('@aws-amplify/core', () => ({
Expand Down Expand Up @@ -106,9 +106,9 @@ describe('getUrl test', () => {
const result = await getUrl({
key,
options: {
...(options as StorageOptions),
...options,
validateObjectExistence: true,
},
} as GetUrlOptions,
});
expect(getPresignedGetObjectUrl).toBeCalledTimes(1);
expect(headObject).toBeCalledTimes(1);
Expand Down
16 changes: 10 additions & 6 deletions packages/storage/__tests__/providers/s3/apis/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import { Credentials } from '@aws-sdk/types';
import { Amplify } from '@aws-amplify/core';
import { listObjectsV2 } from '../../../../src/providers/s3/utils/client';
import { list } from '../../../../src/providers/s3/apis';
import { StorageOptions } from '../../../../src/types';
import { list } from '../../../../src/providers/s3';
import {
ListAllOptions,
ListPaginateOptions,
} from '../../../../src/providers/s3/types';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('@aws-amplify/core', () => ({
Expand Down Expand Up @@ -135,7 +138,7 @@ describe('list API', () => {
expect.assertions(4);
let response = await list({
prefix: path,
options: options as StorageOptions,
options: options as ListPaginateOptions,
});
expect(response.items).toEqual([
{ ...listResultItem, key: path ?? '' },
Expand Down Expand Up @@ -170,7 +173,7 @@ describe('list API', () => {
const response = await list({
prefix: path,
options: {
...(options as StorageOptions),
...(options as ListPaginateOptions),
pageSize: customPageSize,
nextToken: nextToken,
},
Expand Down Expand Up @@ -202,9 +205,10 @@ describe('list API', () => {
expect.assertions(3);
let response = await list({
prefix: path,
options: options as StorageOptions,
options: options as ListPaginateOptions,
});
expect(response.items).toEqual([]);
//
expect(response.nextToken).toEqual(undefined);
expect(listObjectsV2).toHaveBeenCalledWith(listObjectClientConfig, {
Bucket: bucket,
Expand All @@ -225,7 +229,7 @@ describe('list API', () => {
mockListObjectsV2ApiWithPages(3);
const result = await list({
prefix: path,
options: { ...(options as StorageOptions), listAll: true },
options: { ...options, listAll: true } as ListAllOptions,
});

const listResult = { ...listResultItem, key: path ?? '' };
Expand Down

0 comments on commit 939bf37

Please sign in to comment.