Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/storage/__tests__/internals/apis/copy.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AmplifyClassV6 } from '@aws-amplify/core';

import { copy as advancedCopy } from '../../../src/internals';
import { copy as copyInternal } from '../../../src/providers/s3/apis/internal/copy';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';

jest.mock('../../../src/providers/s3/apis/internal/copy');
const mockedCopyInternal = jest.mocked(copyInternal);
const mockCtx = createMockAmplifyContext();

describe('copy (internals)', () => {
beforeEach(() => {
Expand Down Expand Up @@ -44,10 +45,10 @@ describe('copy (internals)', () => {
customEndpoint,
},
};
const result = await advancedCopy(copyInputWithAdvancedOptions);
const result = await advancedCopy(mockCtx, copyInputWithAdvancedOptions);
expect(mockedCopyInternal).toHaveBeenCalledTimes(1);
expect(mockedCopyInternal).toHaveBeenCalledWith(
expect.any(AmplifyClassV6),
mockCtx,
copyInputWithAdvancedOptions,
);
expect(result).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import { downloadData as advancedDownloadData } from '../../../src/internals';
import { downloadData as downloadDataInternal } from '../../../src/providers/s3/apis/internal/downloadData';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';

jest.mock('../../../src/providers/s3/apis/internal/downloadData');
const mockedDownloadDataInternal = jest.mocked(downloadDataInternal);
const mockCtx = createMockAmplifyContext();

describe('downloadData (internal)', () => {
beforeEach(() => {
Expand Down Expand Up @@ -43,7 +45,7 @@ describe('downloadData (internal)', () => {
const onProgress = jest.fn();
const bytesRange = { start: 1024, end: 2048 };

const output = await advancedDownloadData({
const output = await advancedDownloadData(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
Expand All @@ -57,7 +59,7 @@ describe('downloadData (internal)', () => {
});

expect(mockedDownloadDataInternal).toHaveBeenCalledTimes(1);
expect(mockedDownloadDataInternal).toHaveBeenCalledWith({
expect(mockedDownloadDataInternal).toHaveBeenCalledWith(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
Expand Down
26 changes: 12 additions & 14 deletions packages/storage/__tests__/internals/apis/getProperties.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AmplifyClassV6 } from '@aws-amplify/core';

import { getProperties as advancedGetProperties } from '../../../src/internals';
import { getProperties as getPropertiesInternal } from '../../../src/providers/s3/apis/internal/getProperties';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';

jest.mock('../../../src/providers/s3/apis/internal/getProperties');
const mockedGetPropertiesInternal = jest.mocked(getPropertiesInternal);
const mockCtx = createMockAmplifyContext();

describe('getProperties (internal)', () => {
beforeEach(() => {
Expand All @@ -32,7 +33,7 @@ describe('getProperties (internal)', () => {
expiration: new Date(),
},
});
const result = await advancedGetProperties({
const result = await advancedGetProperties(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
Expand All @@ -43,19 +44,16 @@ describe('getProperties (internal)', () => {
},
});
expect(mockedGetPropertiesInternal).toHaveBeenCalledTimes(1);
expect(mockedGetPropertiesInternal).toHaveBeenCalledWith(
expect.any(AmplifyClassV6),
{
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
expectedBucketOwner,
locationCredentialsProvider,
},
expect(mockedGetPropertiesInternal).toHaveBeenCalledWith(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
expectedBucketOwner,
locationCredentialsProvider,
},
);
});
expect(result).toEqual({
path: 'output/path/to/mock/object',
});
Expand Down
34 changes: 16 additions & 18 deletions packages/storage/__tests__/internals/apis/getUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AmplifyClassV6 } from '@aws-amplify/core';

import { getUrl as advancedGetUrl } from '../../../src/internals';
import { getUrl as getUrlInternal } from '../../../src/providers/s3/apis/internal/getUrl';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';

jest.mock('../../../src/providers/s3/apis/internal/getUrl');
const mockedGetUrlInternal = jest.mocked(getUrlInternal);
const mockCtx = createMockAmplifyContext();

const MOCK_URL = new URL('https://s3.aws/mock-presigned-url');
const MOCK_DATE = new Date();
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('getUrl (internal)', () => {
expiration: new Date(),
},
});
const result = await advancedGetUrl({
const result = await advancedGetUrl(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
Expand All @@ -56,23 +57,20 @@ describe('getUrl (internal)', () => {
},
});
expect(mockedGetUrlInternal).toHaveBeenCalledTimes(1);
expect(mockedGetUrlInternal).toHaveBeenCalledWith(
expect.any(AmplifyClassV6),
{
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
validateObjectExistence,
expiresIn,
contentDisposition,
contentType,
expectedBucketOwner,
locationCredentialsProvider,
},
expect(mockedGetUrlInternal).toHaveBeenCalledWith(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
validateObjectExistence,
expiresIn,
contentDisposition,
contentType,
expectedBucketOwner,
locationCredentialsProvider,
},
);
});
expect(result).toEqual({
url: MOCK_URL,
expiresAt: MOCK_DATE,
Expand Down
26 changes: 12 additions & 14 deletions packages/storage/__tests__/internals/apis/list.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AmplifyClassV6 } from '@aws-amplify/core';

import { list as advancedList } from '../../../src/internals';
import { list as listInternal } from '../../../src/providers/s3/apis/internal/list';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';

jest.mock('../../../src/providers/s3/apis/internal/list');
const mockedListInternal = jest.mocked(listInternal);
const mockCtx = createMockAmplifyContext();

describe('list (internals)', () => {
beforeEach(() => {
Expand All @@ -29,7 +30,7 @@ describe('list (internals)', () => {
expiration: new Date(),
},
});
const result = await advancedList({
const result = await advancedList(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
Expand All @@ -40,19 +41,16 @@ describe('list (internals)', () => {
},
});
expect(mockedListInternal).toHaveBeenCalledTimes(1);
expect(mockedListInternal).toHaveBeenCalledWith(
expect.any(AmplifyClassV6),
{
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
expectedBucketOwner,
locationCredentialsProvider,
},
expect(mockedListInternal).toHaveBeenCalledWith(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
expectedBucketOwner,
locationCredentialsProvider,
},
);
});
expect(result).toEqual({
items: [],
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Amplify, AuthTokens, fetchAuthSession } from '@aws-amplify/core';
import { AmplifyContext, AuthTokens } from '@aws-amplify/core';

import { resolveLocationsForCurrentSession } from '../../../../src/internals/apis/listPaths/resolveLocationsForCurrentSession';
import { getHighestPrecedenceUserGroup } from '../../../../src/internals/apis/listPaths/getHighestPrecedenceUserGroup';
import { listPaths } from '../../../../src/internals';

jest.mock('@aws-amplify/core', () => ({
ConsoleLogger: jest.fn(),
Amplify: {
getConfig: jest.fn(),
Auth: {
getConfig: jest.fn(),
fetchAuthSession: jest.fn(),
},
},
fetchAuthSession: jest.fn(),
}));
jest.mock(
'../../../../src/internals/apis/listPaths/resolveLocationsForCurrentSession',
);
Expand All @@ -32,8 +21,20 @@ const credentials = {
};
const identityId = 'identityId';

const mockGetConfig = jest.mocked(Amplify.getConfig);
const mockFetchAuthSession = jest.mocked(fetchAuthSession);
const mockGetConfig = jest.fn();
const mockFetchAuthSession = jest.fn();
// listPaths now receives a required AmplifyContext. Back resourcesConfig with
// a jest.fn so tests can vary config per-case, and expose fetchAuthSession as a
// jest.fn for session/token control.
const mockCtx: AmplifyContext = {
get resourcesConfig() {
return mockGetConfig();
},
libraryOptions: {},
fetchAuthSession: mockFetchAuthSession,
clearCredentials: jest.fn(),
getTokens: jest.fn(),
};
const mockResolveLocationsFromCurrentSession =
resolveLocationsForCurrentSession as jest.Mock;
const mockGetHighestPrecedenceUserGroup = jest.mocked(
Expand Down Expand Up @@ -99,7 +100,7 @@ describe('listPaths', () => {
Storage: { S3: { buckets: undefined } },
});

const result = await listPaths();
const result = await listPaths(mockCtx);

expect(result).toEqual({ locations: [] });
});
Expand All @@ -118,7 +119,7 @@ describe('listPaths', () => {
},
]);

const result = await listPaths();
const result = await listPaths(mockCtx);

expect(result).toEqual({
locations: [
Expand Down Expand Up @@ -157,7 +158,7 @@ describe('listPaths', () => {
prefix: '/path1',
},
});
await listPaths();
await listPaths(mockCtx);

expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalled();
expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalledWith({
Expand Down Expand Up @@ -189,7 +190,7 @@ describe('listPaths', () => {
});
mockGetHighestPrecedenceUserGroup.mockReturnValue('admin');

await listPaths();
await listPaths(mockCtx);

expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalled();
expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalledWith({
Expand Down
26 changes: 12 additions & 14 deletions packages/storage/__tests__/internals/apis/remove.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AmplifyClassV6 } from '@aws-amplify/core';

import { remove as advancedRemove } from '../../../src/internals';
import { remove as removeInternal } from '../../../src/providers/s3/apis/internal/remove';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';

jest.mock('../../../src/providers/s3/apis/internal/remove');
const mockedRemoveInternal = jest.mocked(removeInternal);
const mockCtx = createMockAmplifyContext();

describe('remove (internal)', () => {
beforeEach(() => {
Expand All @@ -33,7 +34,7 @@ describe('remove (internal)', () => {
},
});

const result = await advancedRemove({
const result = await advancedRemove(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
Expand All @@ -45,19 +46,16 @@ describe('remove (internal)', () => {
});

expect(mockedRemoveInternal).toHaveBeenCalledTimes(1);
expect(mockedRemoveInternal).toHaveBeenCalledWith(
expect.any(AmplifyClassV6),
{
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
expectedBucketOwner,
locationCredentialsProvider,
},
expect(mockedRemoveInternal).toHaveBeenCalledWith(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
expectedBucketOwner,
locationCredentialsProvider,
},
);
});
expect(result).toEqual({
path: 'output/path/to/mock/object',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import { uploadData as advancedUploadData } from '../../../src/internals';
import { uploadData as uploadDataInternal } from '../../../src/providers/s3/apis/internal/uploadData';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';

jest.mock('../../../src/providers/s3/apis/internal/uploadData');
const mockedUploadDataInternal = jest.mocked(uploadDataInternal);
const mockedUploadTask = 'UPLOAD_TASK';
const mockCtx = createMockAmplifyContext();

const expectedCtx = {
amplify: Amplify,
amplify: mockCtx,
readFile: expect.any(Function),
toBase64: expect.any(Function),
};
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('uploadData (internal)', () => {
const onProgress = jest.fn();
const metadata = { foo: 'bar' };

const result = advancedUploadData({
const result = advancedUploadData(mockCtx, {
path: 'input/path/to/mock/object',
data: 'data',
options: {
Expand Down
Loading
Loading