Skip to content

Commit

Permalink
release(required): Amplify JS release (#13942)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhengshs authored Oct 21, 2024
2 parents 554c3d5 + bf58ebc commit d0e6e69
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1.bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ body:
multiple: false
options:
- Amplify CLI
- Amplify Gen 2 (Preview)
- Amplify Gen 2
- CDK
- Other
- type: textarea
Expand Down
19 changes: 12 additions & 7 deletions packages/core/__tests__/Cache/StorageCacheCommon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defaultConfig } from '../../src/Cache/constants';
import { StorageCacheCommon } from '../../src/Cache/StorageCacheCommon';
import { KeyValueStorageInterface } from '../../src/types';
import { ConsoleLogger } from '../../src/Logger';
import { StorageCache } from '../../src/Cache/StorageCache';
import {
getByteLength,
getCurrentSizeKey,
Expand Down Expand Up @@ -584,16 +585,20 @@ describe('StorageCacheCommon', () => {
});

describe('clear()', () => {
const cache = getStorageCache(config);
const cache = new StorageCache(config);

it('clears the cache, including the currentSizeKey', async () => {
mockGetAllCacheKeys.mockReturnValue([
currentSizeKey,
`${keyPrefix}some-key`,
]);
await cache.setItem('key1', 'value1');
await cache.setItem('key2', 'value2');

expect(await cache.getItem('key1')).toBe('value1');
expect(await cache.getItem('key2')).toBe('value2');

await cache.clear();
expect(loggerSpy.debug).toHaveBeenCalledWith('Clear Cache');
expect(mockKeyValueStorageRemoveItem).toHaveBeenCalledTimes(2);

expect(await cache.getItem('key1')).toBeNull();
expect(await cache.getItem('key2')).toBeNull();
expect(await cache.getCurrentCacheSize()).toBe(0);
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/Cache/StorageCacheCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ export abstract class StorageCacheCommon {
try {
const keys = await this.getAllKeys();
for (const key of keys) {
await this.getStorage().removeItem(key);
const prefixedKey = `${this.config.keyPrefix}${key}`;
await this.getStorage().removeItem(prefixedKey);
}
} catch (e) {
logger.warn(`clear failed! ${e}`);
Expand Down
41 changes: 41 additions & 0 deletions packages/storage/__tests__/providers/s3/apis/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,47 @@ describe('list API', () => {
},
);

it.each(pathTestCases)(
'should list objects with CommonPrefix and nextToken in results with custom path: $path',
async ({ path }) => {
mockListObject.mockImplementationOnce(() => {
return {
CommonPrefixes: [
{ Prefix: 'photos/2023/' },
{ Prefix: 'photos/2024/' },
{ Prefix: 'photos/2025/' },
{ Prefix: 'photos/2026/' },
{ Prefix: 'photos/2027/' },
{ Prefix: 'photos/time-traveling/' },
],
NextContinuationToken: 'yup_there_is_more',
};
});
const response = await listPaginatedWrapper({
path: resolvePath(path),
});
expect(response.excludedSubpaths).toEqual([
'photos/2023/',
'photos/2024/',
'photos/2025/',
'photos/2026/',
'photos/2027/',
'photos/time-traveling/',
]);

expect(response.nextToken).toEqual('yup_there_is_more');
expect(listObjectsV2).toHaveBeenCalledTimes(1);
await expect(listObjectsV2).toBeLastCalledWithConfigAndInput(
listObjectClientConfig,
{
Bucket: bucket,
MaxKeys: 1000,
Prefix: resolvePath(path),
},
);
},
);

it.each(pathTestCases)(
'should list all objects having three pages with custom path: $path',
async ({ path: inputPath }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ describe('uploadData with path', () => {
},
);

it('should use putObject for 0 bytes data (e.g. create a folder)', () => {
const testInput = {
path: 'test-path',
data: '', // 0 bytes
};

uploadData(testInput);

expect(mockPutObjectJob).toHaveBeenCalledWith(
testInput,
expect.any(AbortSignal),
expect.any(Number),
);
expect(mockGetMultipartUploadHandlers).not.toHaveBeenCalled();
});

it('should use uploadTask', async () => {
mockPutObjectJob.mockReturnValueOnce('putObjectJob');
mockCreateUploadTask.mockReturnValueOnce('uploadTask');
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/internal/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const _listWithPath = async ({
if (!contents) {
return {
items: [],
nextToken: nextContinuationToken,
excludedSubpaths,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/src/providers/s3/apis/uploadData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function uploadData(input: UploadDataInput | UploadDataWithPathInput) {
StorageValidationErrorCode.ObjectIsTooLarge,
);

if (dataByteLength && dataByteLength <= DEFAULT_PART_SIZE) {
if (dataByteLength !== undefined && dataByteLength <= DEFAULT_PART_SIZE) {
// Single part upload
const abortController = new AbortController();

Expand Down

0 comments on commit d0e6e69

Please sign in to comment.