From 939bf379d37caccff9fd56037da3b499c1274c91 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Wed, 13 Sep 2023 15:39:56 -0700 Subject: [PATCH] fix: more unit tests --- .../providers/s3/apis/downloadData.test.ts | 6 +++--- .../providers/s3/apis/getProperties.test.ts | 4 ++-- .../__tests__/providers/s3/apis/getUrl.test.ts | 6 +++--- .../__tests__/providers/s3/apis/list.test.ts | 16 ++++++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts b/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts index a4b095a6d90..e107f05e6ad 100644 --- a/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts @@ -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'); @@ -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(); diff --git a/packages/storage/__tests__/providers/s3/apis/getProperties.test.ts b/packages/storage/__tests__/providers/s3/apis/getProperties.test.ts index 60765c2a95f..946eac7c245 100644 --- a/packages/storage/__tests__/providers/s3/apis/getProperties.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/getProperties.test.ts @@ -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', () => ({ @@ -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); diff --git a/packages/storage/__tests__/providers/s3/apis/getUrl.test.ts b/packages/storage/__tests__/providers/s3/apis/getUrl.test.ts index 74b992f18c2..5fb759584e8 100644 --- a/packages/storage/__tests__/providers/s3/apis/getUrl.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/getUrl.test.ts @@ -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', () => ({ @@ -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); diff --git a/packages/storage/__tests__/providers/s3/apis/list.test.ts b/packages/storage/__tests__/providers/s3/apis/list.test.ts index fecad15e696..c1bc773127d 100644 --- a/packages/storage/__tests__/providers/s3/apis/list.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/list.test.ts @@ -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', () => ({ @@ -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 ?? '' }, @@ -170,7 +173,7 @@ describe('list API', () => { const response = await list({ prefix: path, options: { - ...(options as StorageOptions), + ...(options as ListPaginateOptions), pageSize: customPageSize, nextToken: nextToken, }, @@ -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, @@ -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 ?? '' };