forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ashwinkumar6/next/release-feat
Next/release feat
- Loading branch information
Showing
20 changed files
with
275 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@aws-amplify/auth/cognito/server", | ||
"main": "../../lib/providers/cognito/apis/server/index.js", | ||
"browser": "../../lib-esm/providers/cognito/apis/server/index.js", | ||
"module": "../../lib-esm/providers/cognito/apis/server/index.js", | ||
"typings": "../../lib-esm/providers/cognito/apis/server/index.d.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
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
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,169 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
ResourcesConfig, | ||
Amplify as AmplifySingleton, | ||
LocalStorage, | ||
CookieStorage, | ||
TokenProvider, | ||
} from '@aws-amplify/core'; | ||
import { | ||
CognitoUserPoolsTokenProvider, | ||
cognitoCredentialsProvider, | ||
} from '../src/auth/cognito'; | ||
|
||
import { Amplify } from '../src'; | ||
|
||
jest.mock('@aws-amplify/core', () => ({ | ||
...jest.requireActual('@aws-amplify/core'), | ||
Amplify: { | ||
configure: jest.fn(), | ||
getConfig: jest.fn(), | ||
}, | ||
LocalStorage: jest.fn(), | ||
CookieStorage: jest.fn(), | ||
})); | ||
|
||
jest.mock('../src/auth/cognito', () => ({ | ||
CognitoUserPoolsTokenProvider: { | ||
setAuthConfig: jest.fn(), | ||
setKeyValueStorage: jest.fn(), | ||
}, | ||
cognitoCredentialsProvider: jest.fn(), | ||
})); | ||
|
||
const mockCognitoUserPoolsTokenProviderSetAuthConfig = | ||
CognitoUserPoolsTokenProvider.setAuthConfig as jest.Mock; | ||
const mockCognitoUserPoolsTokenProviderSetKeyValueStorage = | ||
CognitoUserPoolsTokenProvider.setKeyValueStorage as jest.Mock; | ||
const mockAmplifySingletonConfigure = AmplifySingleton.configure as jest.Mock; | ||
const mockAmplifySingletonGetConfig = AmplifySingleton.getConfig as jest.Mock; | ||
const MockCookieStorage = CookieStorage as jest.Mock; | ||
|
||
const mockResourceConfig: ResourcesConfig = { | ||
Auth: { | ||
Cognito: { | ||
userPoolClientId: 'userPoolClientId', | ||
userPoolId: 'userPoolId', | ||
}, | ||
}, | ||
Storage: { | ||
S3: { | ||
bucket: 'bucket', | ||
region: 'us-west-2', | ||
}, | ||
}, | ||
}; | ||
|
||
describe('initSingleton (DefaultAmplify)', () => { | ||
beforeEach(() => { | ||
mockCognitoUserPoolsTokenProviderSetAuthConfig.mockReset(); | ||
mockCognitoUserPoolsTokenProviderSetKeyValueStorage.mockReset(); | ||
mockAmplifySingletonConfigure.mockReset(); | ||
mockAmplifySingletonGetConfig.mockReset(); | ||
}); | ||
|
||
describe('DefaultAmplify.configure()', () => { | ||
describe('when ResourcesConfig.Auth is defined', () => { | ||
describe('when libraryOptions.Auth is undefined', () => { | ||
it('should invoke AmplifySingleton.configure with the default auth providers', () => { | ||
Amplify.configure(mockResourceConfig); | ||
|
||
expect( | ||
mockCognitoUserPoolsTokenProviderSetAuthConfig | ||
).toHaveBeenCalledWith(mockResourceConfig.Auth); | ||
|
||
expect(mockAmplifySingletonConfigure).toHaveBeenCalledWith( | ||
mockResourceConfig, | ||
{ | ||
Auth: { | ||
tokenProvider: CognitoUserPoolsTokenProvider, | ||
credentialsProvider: cognitoCredentialsProvider, | ||
}, | ||
} | ||
); | ||
}); | ||
|
||
it('should invoke AmplifySingleton.configure with other provided library options', () => { | ||
const libraryOptionsWithStorage = { | ||
Storage: { | ||
S3: { | ||
defaultAccessLevel: 'private', | ||
isObjectLockEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
Amplify.configure(mockResourceConfig, { | ||
Storage: { | ||
S3: { | ||
defaultAccessLevel: 'private', | ||
isObjectLockEnabled: true, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(mockAmplifySingletonConfigure).toHaveBeenCalledWith( | ||
mockResourceConfig, | ||
{ | ||
Auth: { | ||
tokenProvider: CognitoUserPoolsTokenProvider, | ||
credentialsProvider: cognitoCredentialsProvider, | ||
}, | ||
...libraryOptionsWithStorage, | ||
} | ||
); | ||
}); | ||
|
||
it('should use LocalStorage by default for the default CognitoUserPoolsTokenProvider', () => { | ||
Amplify.configure(mockResourceConfig); | ||
|
||
expect( | ||
mockCognitoUserPoolsTokenProviderSetKeyValueStorage | ||
).toHaveBeenCalledWith(LocalStorage); | ||
}); | ||
|
||
it('should use cookie storage if LibraryOptions.ssr is set to true for the default CognitoUserPoolsTokenProvider', () => { | ||
Amplify.configure(mockResourceConfig, { ssr: true }); | ||
|
||
expect(MockCookieStorage).toHaveBeenCalledWith({ | ||
sameSite: 'strict', | ||
}); | ||
expect( | ||
mockCognitoUserPoolsTokenProviderSetKeyValueStorage | ||
).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('when libraryOptions.Auth is defined', () => { | ||
it('should forward the libraryOptions to AmplifySingleton.configure', () => { | ||
const mockTokenProvider: TokenProvider = { | ||
getTokens: jest.fn(), | ||
}; | ||
const mockLibraryOptions = { | ||
Auth: { | ||
tokenProvider: mockTokenProvider, | ||
}, | ||
}; | ||
Amplify.configure(mockResourceConfig, mockLibraryOptions); | ||
|
||
expect(mockAmplifySingletonConfigure).toHaveBeenCalledWith( | ||
mockResourceConfig, | ||
mockLibraryOptions | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('DefaultAmplify.getConfig()', () => { | ||
it('should invoke AmplifySingleton.getConfig and return its result', () => { | ||
mockAmplifySingletonGetConfig.mockReturnValueOnce(mockResourceConfig); | ||
const result = Amplify.getConfig(); | ||
|
||
expect(mockAmplifySingletonGetConfig).toHaveBeenCalledTimes(1); | ||
expect(result).toEqual(mockResourceConfig); | ||
}); | ||
}); | ||
}); |
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,7 @@ | ||
{ | ||
"name": "aws-amplify/auth/cognito/server", | ||
"main": "../../../lib/auth/cognito/server/index.js", | ||
"browser": "../../../lib-esm/auth/cognito/server/index.js", | ||
"module": "../../../lib-esm/auth/cognito/server/index.js", | ||
"typings": "../../../lib-esm/auth/cognito/server/index.d.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
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,7 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/* | ||
This file maps exports from `aws-amplify/auth/cognito/server`. It provides access to server-enabled Cognito APIs. | ||
*/ | ||
export * from '@aws-amplify/auth/cognito/server'; |
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
Oops, something went wrong.