|
| 1 | +import { $TSContext, stateManager } from 'amplify-cli-core'; |
| 2 | +import { getUpdateAuthHandler } from '../../../../provider-utils/awscloudformation/handlers/resource-handlers'; |
| 3 | +import { CognitoConfiguration } from '../../../../provider-utils/awscloudformation/service-walkthrough-types/awsCognito-user-input-types'; |
| 4 | +import { getSupportedServices } from '../../../../provider-utils/supported-services'; |
| 5 | +import { getUpdateAuthDefaultsApplier } from '../../../../provider-utils/awscloudformation/utils/auth-defaults-appliers'; |
| 6 | +import { AuthInputState } from '../../../../provider-utils/awscloudformation/auth-inputs-manager/auth-input-state'; |
| 7 | +import { getPostUpdateAuthMetaUpdater } from '../../../../provider-utils/awscloudformation/utils/amplify-meta-updaters'; |
| 8 | +import { getPostUpdateAuthMessagePrinter } from '../../../../provider-utils/awscloudformation/utils/message-printer'; |
| 9 | +import { removeDeprecatedProps } from '../../../../provider-utils/awscloudformation/utils/synthesize-resources'; |
| 10 | +import {ENV_SPECIFIC_PARAMS} from '../../../../provider-utils/awscloudformation/constants'; |
| 11 | + |
| 12 | +jest.mock('../../../../provider-utils/awscloudformation/utils/synthesize-resources'); |
| 13 | +jest.mock('../../../../provider-utils/awscloudformation/utils/auth-defaults-appliers'); |
| 14 | +jest.mock('../../../../provider-utils/supported-services'); |
| 15 | +jest.mock('../../../../provider-utils/awscloudformation/auth-inputs-manager/auth-input-state'); |
| 16 | +jest.mock('../../../../provider-utils/awscloudformation/utils/generate-auth-stack-template'); |
| 17 | +jest.mock('../../../../provider-utils/awscloudformation/utils/message-printer'); |
| 18 | +// eslint-disable-next-line spellcheck/spell-checker |
| 19 | +jest.mock('../../../../provider-utils/awscloudformation/utils/amplify-meta-updaters'); |
| 20 | +jest.mock('../../../../provider-utils/awscloudformation/utils/auth-sms-workflow-helper'); |
| 21 | +jest.mock('amplify-cli-core'); |
| 22 | + |
| 23 | +const getSupportedServicesMock = getSupportedServices as jest.MockedFunction<typeof getSupportedServices>; |
| 24 | +getSupportedServicesMock.mockReturnValue({ |
| 25 | + test: { |
| 26 | + defaultValuesFilename: 'test', |
| 27 | + }, |
| 28 | +}); |
| 29 | + |
| 30 | +const testConfig = ENV_SPECIFIC_PARAMS.reduce((acc, it) => ({...acc, [it]: 'test'}), {} as Record<string, string>); |
| 31 | +testConfig.nonEnvSpecificParam = 'something'; |
| 32 | + |
| 33 | +const getUpdateAuthDefaultsApplierMock = getUpdateAuthDefaultsApplier as jest.MockedFunction<typeof getUpdateAuthDefaultsApplier>; |
| 34 | +getUpdateAuthDefaultsApplierMock.mockReturnValue(jest.fn().mockReturnValue({ ...testConfig })); |
| 35 | + |
| 36 | +const stateManagerMock = stateManager as jest.Mocked<typeof stateManager>; |
| 37 | +stateManagerMock.getMeta.mockReturnValue({ |
| 38 | + auth: {}, |
| 39 | +}); |
| 40 | + |
| 41 | +const getPostUpdateAuthMetaUpdaterMock = getPostUpdateAuthMetaUpdater as jest.MockedFunction<typeof getPostUpdateAuthMetaUpdater>; |
| 42 | +getPostUpdateAuthMetaUpdaterMock.mockReturnValue(jest.fn()); |
| 43 | + |
| 44 | +const getPostUpdateAuthMessagePrinterMock = getPostUpdateAuthMessagePrinter as jest.MockedFunction<typeof getPostUpdateAuthMessagePrinter>; |
| 45 | +getPostUpdateAuthMessagePrinterMock.mockReturnValue(jest.fn()); |
| 46 | + |
| 47 | +const removeDeprecatedPropsMock = removeDeprecatedProps as jest.MockedFunction<typeof removeDeprecatedProps>; |
| 48 | +removeDeprecatedPropsMock.mockImplementation(input => input); |
| 49 | + |
| 50 | +const AuthInputStateMock = AuthInputState as jest.MockedClass<typeof AuthInputState>; |
| 51 | +const saveCLIInputPayloadMock = jest.fn(); |
| 52 | +AuthInputStateMock.mockImplementation(() => ({ |
| 53 | + saveCLIInputPayload: saveCLIInputPayloadMock, |
| 54 | +} as unknown as AuthInputState)); |
| 55 | + |
| 56 | +describe('getUpdateAuthHandler', () => { |
| 57 | + it('filters cliInputs on env specific params', async () => { |
| 58 | + const saveParamsFn = jest.fn(); |
| 59 | + const contextStub = { |
| 60 | + amplify: { |
| 61 | + saveEnvResourceParameters: saveParamsFn, |
| 62 | + }, |
| 63 | + } as unknown as $TSContext; |
| 64 | + const cognitoConfig: CognitoConfiguration = { |
| 65 | + serviceName: 'test', |
| 66 | + } as unknown as CognitoConfiguration; |
| 67 | + |
| 68 | + await getUpdateAuthHandler(contextStub)(cognitoConfig); |
| 69 | + const {cognitoConfig: actualCliInputsFileContent} = saveCLIInputPayloadMock.mock.calls[0][0]; |
| 70 | + expect(Object.keys(actualCliInputsFileContent).some(key => ENV_SPECIFIC_PARAMS.includes(key))).toBe(false); |
| 71 | + expect(actualCliInputsFileContent.nonEnvSpecificParam).toBe('something'); |
| 72 | + }); |
| 73 | +}); |
0 commit comments