-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(storage): add server api unit test
- Loading branch information
1 parent
9ebaadd
commit fb30a25
Showing
6 changed files
with
299 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/storage/__tests__/providers/s3/apis/server/copy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getAmplifyServerContext } from '@aws-amplify/core/internals/adapter-core'; | ||
|
||
import { CopyInput, CopyWithPathInput } from '../../../../../src'; | ||
import { copy } from '../../../../../src/providers/s3/apis/server'; | ||
import { copy as internalCopyImpl } from '../../../../../src/providers/s3/apis/internal/copy'; | ||
|
||
jest.mock('../../../../../src/providers/s3/apis/internal/copy'); | ||
jest.mock('@aws-amplify/core/internals/adapter-core'); | ||
|
||
const mockInternalCopyImpl = jest.mocked(internalCopyImpl); | ||
const mockGetAmplifyServerContext = jest.mocked(getAmplifyServerContext); | ||
const mockInternalResult = 'RESULT' as any; | ||
const mockAmplifyClass = 'AMPLIFY_CLASS' as any; | ||
const mockAmplifyContextSpec = { | ||
token: { value: Symbol('123') }, | ||
}; | ||
|
||
describe('server-side copy', () => { | ||
beforeEach(() => { | ||
mockGetAmplifyServerContext.mockReturnValue({ | ||
amplify: mockAmplifyClass, | ||
}); | ||
mockInternalCopyImpl.mockReturnValue(mockInternalResult); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass through input with key and output to internal implementation', async () => { | ||
const input: CopyInput = { | ||
source: { | ||
key: 'source-key', | ||
}, | ||
destination: { | ||
key: 'destination-key', | ||
}, | ||
}; | ||
expect(copy(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalCopyImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
|
||
it('should pass through input with path and output to internal implementation', async () => { | ||
const input: CopyWithPathInput = { | ||
source: { path: 'abc' }, | ||
destination: { path: 'abc' }, | ||
}; | ||
expect(copy(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalCopyImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
packages/storage/__tests__/providers/s3/apis/server/getProperties.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getAmplifyServerContext } from '@aws-amplify/core/internals/adapter-core'; | ||
|
||
import { | ||
GetPropertiesInput, | ||
GetPropertiesWithPathInput, | ||
} from '../../../../../src'; | ||
import { getProperties } from '../../../../../src/providers/s3/apis/server'; | ||
import { getProperties as internalGetPropertiesImpl } from '../../../../../src/providers/s3/apis/internal/getProperties'; | ||
|
||
jest.mock('../../../../../src/providers/s3/apis/internal/getProperties'); | ||
jest.mock('@aws-amplify/core/internals/adapter-core'); | ||
|
||
const mockInternalGetPropertiesImpl = jest.mocked(internalGetPropertiesImpl); | ||
const mockGetAmplifyServerContext = jest.mocked(getAmplifyServerContext); | ||
const mockInternalResult = 'RESULT' as any; | ||
const mockAmplifyClass = 'AMPLIFY_CLASS' as any; | ||
const mockAmplifyContextSpec = { | ||
token: { value: Symbol('123') }, | ||
}; | ||
|
||
describe('server-side getProperties', () => { | ||
beforeEach(() => { | ||
mockGetAmplifyServerContext.mockReturnValue({ | ||
amplify: mockAmplifyClass, | ||
}); | ||
mockInternalGetPropertiesImpl.mockReturnValue(mockInternalResult); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass through input with key and output to internal implementation', async () => { | ||
const input: GetPropertiesInput = { | ||
key: 'source-key', | ||
}; | ||
expect(getProperties(mockAmplifyContextSpec, input)).toEqual( | ||
mockInternalResult, | ||
); | ||
expect(mockInternalGetPropertiesImpl).toBeCalledWith( | ||
mockAmplifyClass, | ||
input, | ||
); | ||
}); | ||
|
||
it('should pass through input with path and output to internal implementation', async () => { | ||
const input: GetPropertiesWithPathInput = { | ||
path: 'abc', | ||
}; | ||
expect(getProperties(mockAmplifyContextSpec, input)).toEqual( | ||
mockInternalResult, | ||
); | ||
expect(mockInternalGetPropertiesImpl).toBeCalledWith( | ||
mockAmplifyClass, | ||
input, | ||
); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
packages/storage/__tests__/providers/s3/apis/server/getUrl.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getAmplifyServerContext } from '@aws-amplify/core/internals/adapter-core'; | ||
|
||
import { GetUrlInput, GetUrlWithPathInput } from '../../../../../src'; | ||
import { getUrl } from '../../../../../src/providers/s3/apis/server'; | ||
import { getUrl as internalGetUrlImpl } from '../../../../../src/providers/s3/apis/internal/getUrl'; | ||
|
||
jest.mock('../../../../../src/providers/s3/apis/internal/getUrl'); | ||
jest.mock('@aws-amplify/core/internals/adapter-core'); | ||
|
||
const mockInternalGetUrlImpl = jest.mocked(internalGetUrlImpl); | ||
const mockGetAmplifyServerContext = jest.mocked(getAmplifyServerContext); | ||
const mockInternalResult = 'RESULT' as any; | ||
const mockAmplifyClass = 'AMPLIFY_CLASS' as any; | ||
|
||
describe('server-side getUrl', () => { | ||
beforeEach(() => { | ||
mockGetAmplifyServerContext.mockReturnValue({ | ||
amplify: mockAmplifyClass, | ||
}); | ||
mockInternalGetUrlImpl.mockReturnValue(mockInternalResult); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass through input with key and output to internal implementation', async () => { | ||
const input: GetUrlInput = { | ||
key: 'source-key', | ||
}; | ||
expect( | ||
getUrl( | ||
{ | ||
token: { value: Symbol('123') }, | ||
}, | ||
input, | ||
), | ||
).toEqual(mockInternalResult); | ||
expect(mockInternalGetUrlImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
|
||
it('should pass through input with path and output to internal implementation', async () => { | ||
const input: GetUrlWithPathInput = { | ||
path: 'abc', | ||
}; | ||
expect( | ||
getUrl( | ||
{ | ||
token: { value: Symbol('123') }, | ||
}, | ||
input, | ||
), | ||
).toEqual(mockInternalResult); | ||
expect(mockInternalGetUrlImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
packages/storage/__tests__/providers/s3/apis/server/list.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getAmplifyServerContext } from '@aws-amplify/core/internals/adapter-core'; | ||
|
||
import { | ||
ListAllInput, | ||
ListAllWithPathInput, | ||
ListPaginateInput, | ||
ListPaginateWithPathInput, | ||
} from '../../../../../src'; | ||
import { list } from '../../../../../src/providers/s3/apis/server'; | ||
import { list as internalListImpl } from '../../../../../src/providers/s3/apis/internal/list'; | ||
|
||
jest.mock('../../../../../src/providers/s3/apis/internal/list'); | ||
jest.mock('@aws-amplify/core/internals/adapter-core'); | ||
|
||
const mockInternalListImpl = jest.mocked(internalListImpl); | ||
const mockGetAmplifyServerContext = jest.mocked(getAmplifyServerContext); | ||
const mockInternalResult = 'RESULT' as any; | ||
const mockAmplifyClass = 'AMPLIFY_CLASS' as any; | ||
const mockAmplifyContextSpec = { | ||
token: { value: Symbol('123') }, | ||
}; | ||
|
||
describe('server-side list', () => { | ||
beforeEach(() => { | ||
mockGetAmplifyServerContext.mockReturnValue({ | ||
amplify: mockAmplifyClass, | ||
}); | ||
mockInternalListImpl.mockReturnValue(mockInternalResult); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass through list all input with key and output to internal implementation', async () => { | ||
const input: ListAllInput = { | ||
prefix: 'source-key', | ||
}; | ||
expect(list(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalListImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
|
||
it('should pass through list paginate input with key and output to internal implementation', async () => { | ||
const input: ListPaginateInput = { | ||
prefix: 'source-key', | ||
options: { | ||
nextToken: '123', | ||
pageSize: 10, | ||
}, | ||
}; | ||
expect(list(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalListImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
|
||
it('should pass through list all input with path and output to internal implementation', async () => { | ||
const input: ListAllWithPathInput = { | ||
path: 'abc', | ||
}; | ||
expect(list(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalListImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
|
||
it('should pass through list paginate input with path and output to internal implementation', async () => { | ||
const input: ListPaginateWithPathInput = { | ||
path: 'abc', | ||
options: { | ||
nextToken: '123', | ||
pageSize: 10, | ||
}, | ||
}; | ||
expect(list(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalListImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/storage/__tests__/providers/s3/apis/server/remove.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getAmplifyServerContext } from '@aws-amplify/core/internals/adapter-core'; | ||
|
||
import { RemoveInput, RemoveWithPathInput } from '../../../../../src'; | ||
import { remove } from '../../../../../src/providers/s3/apis/server'; | ||
import { remove as internalRemoveImpl } from '../../../../../src/providers/s3/apis/internal/remove'; | ||
|
||
jest.mock('../../../../../src/providers/s3/apis/internal/remove'); | ||
jest.mock('@aws-amplify/core/internals/adapter-core'); | ||
|
||
const mockInternalRemoveImpl = jest.mocked(internalRemoveImpl); | ||
const mockGetAmplifyServerContext = jest.mocked(getAmplifyServerContext); | ||
const mockInternalResult = 'RESULT' as any; | ||
const mockAmplifyClass = 'AMPLIFY_CLASS' as any; | ||
const mockAmplifyContextSpec = { | ||
token: { value: Symbol('123') }, | ||
}; | ||
|
||
describe('client-side remove', () => { | ||
beforeEach(() => { | ||
mockGetAmplifyServerContext.mockReturnValue({ | ||
amplify: mockAmplifyClass, | ||
}); | ||
mockInternalRemoveImpl.mockReturnValue(mockInternalResult); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass through input with key and output to internal implementation', async () => { | ||
const input: RemoveInput = { | ||
key: 'source-key', | ||
}; | ||
expect(remove(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalRemoveImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
|
||
it('should pass through input with path and output to internal implementation', async () => { | ||
const input: RemoveWithPathInput = { | ||
path: 'abc', | ||
}; | ||
expect(remove(mockAmplifyContextSpec, input)).toEqual(mockInternalResult); | ||
expect(mockInternalRemoveImpl).toBeCalledWith(mockAmplifyClass, input); | ||
}); | ||
}); |