-
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
102 changed files
with
1,400 additions
and
1,423 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
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './providers/pinpoint'; | ||
export { | ||
record, | ||
identifyUser, | ||
RecordInput, | ||
IdentifyUserInput, | ||
} from './providers/pinpoint'; | ||
export { AnalyticsError } from './errors'; |
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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './apis'; | ||
export { | ||
record, | ||
identifyUser | ||
} from './apis'; | ||
export { | ||
RecordInput, | ||
IdentifyUserInput | ||
} from './types/inputs'; |
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.