-
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.
Feat: Add pagination to Amplify Default Auth storage Browser (#13897)
* update the listLocation handler * implement memoization * add pagination logic * update usergroup logic & test * update getPaginated Locations * fix failing test
- Loading branch information
Showing
12 changed files
with
324 additions
and
38 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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
...ages/storage/__tests__/internals/amplifyAuthAdapter/getHighestPrecedenceUserGroup.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,57 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
UserGroupConfig, | ||
getHighestPrecedenceUserGroup, | ||
} from '../../../src/internals/amplifyAuthConfigAdapter/getHighestPrecedenceUserGroup'; | ||
|
||
const userGroupsFromConfig: UserGroupConfig = [ | ||
{ | ||
editor: { | ||
precedence: 0, | ||
}, | ||
}, | ||
{ | ||
admin: { | ||
precedence: 1, | ||
}, | ||
}, | ||
{ | ||
auditor: { | ||
precedence: 2, | ||
}, | ||
}, | ||
]; | ||
const currentUserGroups = ['guest', 'user', 'admin']; | ||
|
||
describe('getHighestPrecedenceUserGroup', () => { | ||
it('should return the user group with the highest precedence', () => { | ||
const result = getHighestPrecedenceUserGroup( | ||
userGroupsFromConfig, | ||
currentUserGroups, | ||
); | ||
expect(result).toBe('admin'); | ||
}); | ||
|
||
it('should return undefined if userGroupsFromConfig is undefined', () => { | ||
const result = getHighestPrecedenceUserGroup(undefined, currentUserGroups); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return undefined if currentUserGroups is undefined', () => { | ||
const result = getHighestPrecedenceUserGroup( | ||
userGroupsFromConfig, | ||
undefined, | ||
); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should handle currentUserGroups containing groups not present in userGroupsFromConfig', () => { | ||
const result = getHighestPrecedenceUserGroup(userGroupsFromConfig, [ | ||
'unknown', | ||
'user', | ||
]); | ||
expect(result).toBe(undefined); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
packages/storage/__tests__/internals/amplifyAuthAdapter/getPaginatedLocations.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,90 @@ | ||
import { getPaginatedLocations } from '../../../src/internals/amplifyAuthConfigAdapter/getPaginatedLocations'; | ||
import { PathAccess } from '../../../src/internals/types/credentials'; | ||
|
||
describe('getPaginatedLocations', () => { | ||
const mockLocations: PathAccess[] = [ | ||
{ | ||
type: 'PREFIX', | ||
permission: ['read'], | ||
bucket: 'bucket1', | ||
prefix: 'path1/', | ||
}, | ||
{ | ||
type: 'PREFIX', | ||
permission: ['write'], | ||
bucket: 'bucket2', | ||
prefix: 'path2/', | ||
}, | ||
{ | ||
type: 'PREFIX', | ||
permission: ['read', 'write'], | ||
bucket: 'bucket3', | ||
prefix: 'path3/', | ||
}, | ||
]; | ||
|
||
it('should return all locations when no pagination is specified', () => { | ||
const result = getPaginatedLocations({ locations: mockLocations }); | ||
expect(result).toEqual({ locations: mockLocations }); | ||
}); | ||
|
||
it('should return paginated locations when pageSize is specified', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 2, | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(0, 2), | ||
nextToken: '1', | ||
}); | ||
}); | ||
|
||
it('should return paginated locations when pageSize and nextToken are specified', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 1, | ||
nextToken: '2', | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(1, 2), | ||
nextToken: '1', | ||
}); | ||
}); | ||
|
||
it('should return empty locations when locations array is empty', () => { | ||
const result = getPaginatedLocations({ locations: [], pageSize: 2 }); | ||
expect(result).toEqual({ locations: [] }); | ||
}); | ||
|
||
it('should return empty location when nextToken is beyond array length', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 2, | ||
nextToken: '5', | ||
}); | ||
expect(result).toEqual({ locations: [], nextToken: undefined }); | ||
}); | ||
|
||
it('should return all remaining location when page size is greater than remaining locations length', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 5, | ||
nextToken: '2', | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(-2), | ||
nextToken: undefined, | ||
}); | ||
}); | ||
|
||
it('should return undefined nextToken when end of array is reached', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 5, | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(0, 3), | ||
nextToken: undefined, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.