-
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.
- Loading branch information
Showing
63 changed files
with
810 additions
and
450 deletions.
There are no files selected for viewing
44 changes: 32 additions & 12 deletions
44
packages/adapter-nextjs/__tests__/utils/getAmplifyConfig.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 |
---|---|---|
@@ -1,32 +1,52 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { NextConfig } from 'next'; | ||
import getConfig from 'next/config'; | ||
import { getAmplifyConfig } from '../../src/utils/getAmplifyConfig'; | ||
import { AmplifyError } from '@aws-amplify/core/internals/utils'; | ||
|
||
jest.mock('next/config'); | ||
|
||
const mockGetConfig = getConfig as jest.Mock; | ||
|
||
describe('getAmplifyConfig', () => { | ||
const mockAmplifyConfig = { | ||
Auth: { | ||
identityPoolId: '123', | ||
userPoolId: 'abc', | ||
userPoolWebClientId: 'def', | ||
}, | ||
Storage: { | ||
bucket: 'bucket', | ||
region: 'us-east-1', | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
mockGetConfig.mockReturnValue({}); | ||
delete process.env.amplifyConfig; | ||
}); | ||
|
||
it('should return amplifyConfig from env vars', () => { | ||
const mockAmplifyConfig = { | ||
Auth: { | ||
identityPoolId: '123', | ||
userPoolId: 'abc', | ||
userPoolWebClientId: 'def', | ||
}, | ||
Storage: { | ||
bucket: 'bucket', | ||
region: 'us-east-1', | ||
}, | ||
}; | ||
process.env.amplifyConfig = JSON.stringify(mockAmplifyConfig); | ||
|
||
const result = getAmplifyConfig(); | ||
expect(result).toEqual(mockAmplifyConfig); | ||
}); | ||
|
||
it('should attempt to get amplifyConfig via getConfig provided by Next.js as a fallback', () => { | ||
mockGetConfig.mockReturnValueOnce({ | ||
serverRuntimeConfig: { | ||
amplifyConfig: JSON.stringify(mockAmplifyConfig), | ||
}, | ||
}); | ||
|
||
const result = getAmplifyConfig(); | ||
expect(result).toEqual(mockAmplifyConfig); | ||
}); | ||
|
||
it('should throw error when amplifyConfig is not found from env vars', () => { | ||
expect(() => getAmplifyConfig()).toThrowError(); | ||
expect(() => getAmplifyConfig()).toThrow(AmplifyError); | ||
}); | ||
}); |
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,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
Oops, something went wrong.