Skip to content
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

feat: add gen2 path parameter to getProperties and getUrl #13144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3392532
feat: add gen2 path to getProperties API
erinleigh90 Mar 15, 2024
943fde6
test: add unit tests for path parameter
erinleigh90 Mar 15, 2024
265a494
nit: remove unnecessary colon
erinleigh90 Mar 15, 2024
78550ea
feat: add path to types
erinleigh90 Mar 18, 2024
4fdc01f
test: first pass to add path coverage
erinleigh90 Mar 18, 2024
f7df812
Merge branch 'gen2-getProperties' into gen2-getUrl
erinleigh90 Mar 18, 2024
0cad022
fix: adjust tests
erinleigh90 Mar 18, 2024
b2118b3
Merge branch 'gen2-storage' into gen2-getUrl-getProperties
erinleigh90 Mar 19, 2024
23213af
chore: remove links from tsdocs
erinleigh90 Mar 19, 2024
ceaa7a4
test: fix expected Key
erinleigh90 Mar 19, 2024
7b1137d
chore: prettier fix
erinleigh90 Mar 19, 2024
972b655
chore: increase getUrl bundle size
erinleigh90 Mar 19, 2024
2fda5b5
chore: clean up tsdocs in getProperties
erinleigh90 Mar 20, 2024
c3eda69
chore: consolidate constants imports
erinleigh90 Mar 20, 2024
59d541d
test: remove leading slash from path
erinleigh90 Mar 21, 2024
19d6dd8
chore: address feedback
erinleigh90 Mar 21, 2024
a6a4fd0
Merge branch 'gen2-storage' into gen2-getUrl-getProperties
erinleigh90 Mar 22, 2024
d8b4b12
chore: fix test and bundle size check
erinleigh90 Mar 22, 2024
ee54ff3
chore: add back-tics to tsdocs
erinleigh90 Mar 22, 2024
f138c31
chore: use test.each instead of forEach
erinleigh90 Mar 22, 2024
b069077
chore: fix deprecation and tsdocs
erinleigh90 Mar 22, 2024
f3305c8
chore: add contextSpec to copy tsdocs
erinleigh90 Mar 22, 2024
23a5076
Update packages/storage/src/providers/s3/apis/copy.ts
erinleigh90 Mar 22, 2024
b2c4cce
chore: another tsdoc fix
erinleigh90 Mar 22, 2024
644aee1
chore: add tsdocs to server getUrl
erinleigh90 Mar 22, 2024
ec73fc8
address feedback
erinleigh90 Mar 25, 2024
7b530cf
address feedback
erinleigh90 Mar 25, 2024
3b5a402
address feedback
erinleigh90 Mar 25, 2024
30d5b86
chore: add overload for deprecation messaging to getUrl
erinleigh90 Mar 25, 2024
b604e0a
address feedback
erinleigh90 Mar 25, 2024
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
2 changes: 1 addition & 1 deletion packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@
"name": "[Storage] getUrl (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ getUrl }",
"limit": "14.50 kB"
"limit": "14.60 kB"
},
{
"name": "[Storage] list (S3)",
Expand Down
141 changes: 124 additions & 17 deletions packages/storage/__tests__/providers/s3/apis/getProperties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { headObject } from '../../../../src/providers/s3/utils/client';
import { getProperties } from '../../../../src/providers/s3';
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
import { Amplify } from '@aws-amplify/core';
import { GetPropertiesOptions } from '../../../../src/providers/s3/types';
import {
GetPropertiesOptionsKey,
GetPropertiesOptionsPath,
} from '../../../../src/providers/s3/types';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('@aws-amplify/core', () => ({
Expand All @@ -30,10 +33,12 @@ const credentials: AWSCredentials = {
sessionToken: 'sessionToken',
secretAccessKey: 'secretAccessKey',
};
const key = 'key';
const path = 'path';
const targetIdentityId = 'targetIdentityId';
const defaultIdentityId = 'defaultIdentityId';

describe('getProperties api', () => {
describe('getProperties with key', () => {
beforeAll(() => {
mockFetchAuthSession.mockResolvedValue({
credentials,
Expand All @@ -48,9 +53,9 @@ describe('getProperties api', () => {
},
});
});
describe('getProperties happy path ', () => {
describe('Happy cases: With key', () => {
const expected = {
key: 'key',
key,
size: '100',
contentType: 'text/plain',
eTag: 'etag',
Expand All @@ -63,7 +68,6 @@ describe('getProperties api', () => {
region: 'region',
userAgentValue: expect.any(String),
};
const key = 'key';
beforeEach(() => {
mockHeadObject.mockReturnValueOnce({
ContentLength: '100',
Expand All @@ -77,7 +81,7 @@ describe('getProperties api', () => {
afterEach(() => {
jest.clearAllMocks();
});
[
test.each([
{
expectedKey: `public/${key}`,
},
Expand All @@ -97,30 +101,133 @@ describe('getProperties api', () => {
options: { accessLevel: 'protected', targetIdentityId },
expectedKey: `protected/${targetIdentityId}/${key}`,
},
].forEach(({ options, expectedKey }) => {
const accessLevelMsg = options?.accessLevel ?? 'default';
const targetIdentityIdMsg = options?.targetIdentityId
? `and targetIdentityId`
: '';
it(`should getProperties with ${accessLevelMsg} accessLevel ${targetIdentityIdMsg}`, async () => {
])(
'should getProperties with key $expectedKey',
async ({ options, expectedKey }) => {
const headObjectOptions = {
Bucket: 'bucket',
Key: expectedKey,
};
expect.assertions(3);
expect(
await getProperties({
key,
options: options as GetPropertiesOptions,
options: options as GetPropertiesOptionsKey,
}),
).toEqual(expected);
expect(headObject).toHaveBeenCalledTimes(1);
expect(headObject).toHaveBeenCalledWith(config, headObjectOptions);
},
);
});

describe('Error cases : With key', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('getProperties should return a not found error', async () => {
mockHeadObject.mockRejectedValueOnce(
Object.assign(new Error(), {
$metadata: { httpStatusCode: 404 },
name: 'NotFound',
}),
);
expect.assertions(3);
try {
await getProperties({ key });
} catch (error: any) {
expect(headObject).toHaveBeenCalledTimes(1);
expect(headObject).toHaveBeenCalledWith(
{
credentials,
region: 'region',
userAgentValue: expect.any(String),
},
{
Bucket: 'bucket',
Key: `public/${key}`,
},
);
expect(error.$metadata.httpStatusCode).toBe(404);
}
});
});
});

describe('Happy cases: With path', () => {
beforeAll(() => {
mockFetchAuthSession.mockResolvedValue({
credentials,
identityId: defaultIdentityId,
});
mockGetConfig.mockReturnValue({
Storage: {
S3: {
bucket,
region,
},
},
});
});
describe('getProperties with path', () => {
const expected = {
path,
size: '100',
contentType: 'text/plain',
eTag: 'etag',
metadata: { key: 'value' },
lastModified: 'last-modified',
versionId: 'version-id',
};
const config = {
credentials,
region: 'region',
useAccelerateEndpoint: true,
userAgentValue: expect.any(String),
};
beforeEach(() => {
mockHeadObject.mockReturnValueOnce({
ContentLength: '100',
ContentType: 'text/plain',
ETag: 'etag',
LastModified: 'last-modified',
Metadata: { key: 'value' },
VersionId: 'version-id',
});
});
afterEach(() => {
jest.clearAllMocks();
});
test.each([
{
testPath: path,
expectedKey: path,
},
{
testPath: () => path,
expectedKey: path,
},
])(
'should getProperties with path $path and expectedKey $expectedKey',
async ({ testPath, expectedKey }) => {
const headObjectOptions = {
Bucket: 'bucket',
Key: expectedKey,
};
expect(
await getProperties({
path: testPath,
options: {
useAccelerateEndpoint: true,
} as GetPropertiesOptionsPath,
}),
).toEqual(expected);
expect(headObject).toHaveBeenCalledTimes(1);
expect(headObject).toHaveBeenCalledWith(config, headObjectOptions);
},
);
});

describe('getProperties error path', () => {
describe('Error cases : With path', () => {
erinleigh90 marked this conversation as resolved.
Show resolved Hide resolved
afterEach(() => {
jest.clearAllMocks();
});
Expand All @@ -133,7 +240,7 @@ describe('getProperties api', () => {
);
expect.assertions(3);
try {
await getProperties({ key: 'keyed' });
await getProperties({ path });
} catch (error: any) {
expect(headObject).toHaveBeenCalledTimes(1);
expect(headObject).toHaveBeenCalledWith(
Expand All @@ -144,7 +251,7 @@ describe('getProperties api', () => {
},
{
Bucket: 'bucket',
Key: 'public/keyed',
Key: path,
},
);
expect(error.$metadata.httpStatusCode).toBe(404);
Expand Down
Loading
Loading