-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix]: Storage Input/Output types #13270
Changes from all commits
7e743a8
f656f7a
f78dc56
7447bc3
2f9e5d5
41333cb
a248e0f
e34e2ca
708eebc
935a058
515b3cb
2808329
350ca6c
2c0a88d
80448d1
857f152
3c18446
55a587a
771e49e
36d0bf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,16 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AWSCredentials } from '@aws-amplify/core/internals/utils'; | ||
import { Amplify } from '@aws-amplify/core'; | ||
import { Amplify, StorageAccessLevel } from '@aws-amplify/core'; | ||
import { StorageError } from '../../../../src/errors/StorageError'; | ||
import { StorageValidationErrorCode } from '../../../../src/errors/types/validation'; | ||
import { copyObject } from '../../../../src/providers/s3/utils/client'; | ||
import { copy } from '../../../../src/providers/s3/apis'; | ||
import { | ||
CopySourceOptionsWithKey, | ||
CopyDestinationOptionsWithKey, | ||
CopyInput, | ||
CopyWithPathInput, | ||
CopyOutput, | ||
CopyWithPathOutput, | ||
} from '../../../../src/providers/s3/types'; | ||
|
||
jest.mock('../../../../src/providers/s3/utils/client'); | ||
|
@@ -67,6 +69,8 @@ describe('copy API', () => { | |
|
||
describe('Happy Cases', () => { | ||
describe('With key', () => { | ||
const copyWrapper = async (input: CopyInput): Promise<CopyOutput> => | ||
copy(input); | ||
beforeEach(() => { | ||
mockCopyObject.mockImplementation(() => { | ||
return { | ||
|
@@ -77,7 +81,14 @@ describe('copy API', () => { | |
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
[ | ||
const testCases: Array<{ | ||
source: { accessLevel?: StorageAccessLevel; targetIdentityId?: string }; | ||
destination: { | ||
accessLevel?: StorageAccessLevel; | ||
}; | ||
expectedSourceKey: string; | ||
expectedDestinationKey: string; | ||
}> = [ | ||
{ | ||
source: { accessLevel: 'guest' }, | ||
destination: { accessLevel: 'guest' }, | ||
|
@@ -150,7 +161,8 @@ describe('copy API', () => { | |
expectedSourceKey: `${bucket}/protected/${targetIdentityId}/${sourceKey}`, | ||
expectedDestinationKey: `protected/${defaultIdentityId}/${destinationKey}`, | ||
}, | ||
].forEach( | ||
]; | ||
testCases.forEach( | ||
({ | ||
source, | ||
destination, | ||
|
@@ -160,24 +172,18 @@ describe('copy API', () => { | |
const targetIdentityIdMsg = source?.targetIdentityId | ||
? `with targetIdentityId` | ||
: ''; | ||
const copyResult = { | ||
key: destinationKey, | ||
path: expectedDestinationKey, | ||
}; | ||
|
||
it(`should copy ${source.accessLevel} ${targetIdentityIdMsg} -> ${destination.accessLevel}`, async () => { | ||
expect( | ||
await copy({ | ||
source: { | ||
...(source as CopySourceOptionsWithKey), | ||
key: sourceKey, | ||
}, | ||
destination: { | ||
...(destination as CopyDestinationOptionsWithKey), | ||
key: destinationKey, | ||
}, | ||
}), | ||
).toEqual(copyResult); | ||
const { key } = await copyWrapper({ | ||
source: { | ||
...source, | ||
key: sourceKey, | ||
}, | ||
destination: { | ||
...destination, | ||
key: destinationKey, | ||
}, | ||
}); | ||
expect(key).toEqual(destinationKey); | ||
expect(copyObject).toHaveBeenCalledTimes(1); | ||
expect(copyObject).toHaveBeenCalledWith(copyObjectClientConfig, { | ||
...copyObjectClientBaseParams, | ||
|
@@ -190,6 +196,10 @@ describe('copy API', () => { | |
}); | ||
|
||
describe('With path', () => { | ||
const copyWrapper = async ( | ||
input: CopyWithPathInput, | ||
): Promise<CopyWithPathOutput> => copy(input); | ||
Comment on lines
+199
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Possible to hoist this up a few levels to re-use between suites? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So i purposefully did this so we can have both direct usage and wrapper usage. Meaning This is used in all path happy cases but error cases one will have the direct usage. I mean we want to test both ways |
||
|
||
beforeEach(() => { | ||
mockCopyObject.mockImplementation(() => { | ||
return { | ||
|
@@ -222,15 +232,11 @@ describe('copy API', () => { | |
destinationPath, | ||
expectedDestinationPath, | ||
}) => { | ||
expect( | ||
await copy({ | ||
source: { path: sourcePath }, | ||
destination: { path: destinationPath }, | ||
}), | ||
).toEqual({ | ||
path: expectedDestinationPath, | ||
key: expectedDestinationPath, | ||
const { path } = await copyWrapper({ | ||
source: { path: sourcePath }, | ||
destination: { path: destinationPath }, | ||
}); | ||
expect(path).toEqual(expectedDestinationPath); | ||
expect(copyObject).toHaveBeenCalledTimes(1); | ||
expect(copyObject).toHaveBeenCalledWith(copyObjectClientConfig, { | ||
...copyObjectClientBaseParams, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note on this: This is how a customer would have to pass in today if it is not done directly on API call. Please let me know if that is not the case since this is the pattern I followed on all APIs