-
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(auth): support custom identity pool endpoint
- Loading branch information
Showing
7 changed files
with
173 additions
and
57 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
57 changes: 57 additions & 0 deletions
57
...h/__tests__/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.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 @@ | ||
import { AmplifyUrl } from '@aws-amplify/core/internals/utils'; | ||
import { cognitoIdentityPoolEndpointResolver } from '@aws-amplify/core'; | ||
|
||
import { createCognitoIdentityPoolEndpointResolver } from '../../../../src/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver'; | ||
|
||
jest.mock('@aws-amplify/core'); | ||
|
||
const mockCognitoIdentityPoolEndpointResolver = jest.mocked( | ||
cognitoIdentityPoolEndpointResolver, | ||
); | ||
|
||
describe('createCognitoIdentityPoolEndpointResolver()', () => { | ||
afterEach(() => { | ||
mockCognitoIdentityPoolEndpointResolver.mockClear(); | ||
}); | ||
|
||
describe('creating a resolver with overrideEndpoint as `undefined`', () => { | ||
const resolver = createCognitoIdentityPoolEndpointResolver({ | ||
endpointOverride: undefined, | ||
}); | ||
|
||
it('invokes cognitoUserPoolEndpointResolver with the expected region', () => { | ||
const expectedReturningUrl = { | ||
url: new AmplifyUrl( | ||
'https://cognito-identity.us-west-2.amazonaws.com/', | ||
), | ||
}; | ||
mockCognitoIdentityPoolEndpointResolver.mockReturnValueOnce( | ||
expectedReturningUrl, | ||
); | ||
|
||
const expectedRegion = 'us-west-2'; | ||
const { url } = resolver({ region: expectedRegion }); | ||
|
||
expect(mockCognitoIdentityPoolEndpointResolver).toHaveBeenCalledWith({ | ||
region: expectedRegion, | ||
}); | ||
expect(url).toStrictEqual(expectedReturningUrl.url); | ||
}); | ||
}); | ||
|
||
describe('creating a resolver with overrideEndpoint', () => { | ||
const endpointOverride = 'https://cognito-identity.example.com'; | ||
const resolver = createCognitoIdentityPoolEndpointResolver({ | ||
endpointOverride, | ||
}); | ||
|
||
it('returns the endpoint override', () => { | ||
const expectedRegion = 'us-west-2'; | ||
const { url } = resolver({ region: expectedRegion }); | ||
expect(mockCognitoIdentityPoolEndpointResolver).not.toHaveBeenCalled(); | ||
expect(url).toStrictEqual( | ||
new AmplifyUrl('https://cognito-identity.example.com'), | ||
); | ||
}); | ||
}); | ||
}); |
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.