From 675d82ef03ee49c99b9db5b1b5452083ec5e2436 Mon Sep 17 00:00:00 2001 From: akshbhu <39866697+akshbhu@users.noreply.github.com> Date: Mon, 8 Nov 2021 12:50:21 -0800 Subject: [PATCH] fix: headless migrate auth (#8735) --- .../utils/check-for-auth-migration.test.ts | 19 +++++++++++-------- .../utils/check-for-auth-migration.ts | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/check-for-auth-migration.test.ts b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/check-for-auth-migration.test.ts index 9c4dedc834d..d0b22118c77 100644 --- a/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/check-for-auth-migration.test.ts +++ b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/check-for-auth-migration.test.ts @@ -64,10 +64,13 @@ test('migration gets called when cli-inputs doesnt exist', async () => { }); const mockContext = { - amplify : { - getImportedAuthProperties : jest.fn().mockReturnValue({ imported : false }) - } - } + amplify: { + getImportedAuthProperties: jest.fn().mockReturnValue({ imported: false }), + }, + input: { + options: {}, + }, + }; await checkAuthResourceMigration(mockContext as unknown as $TSContext, 'mockResource'); expect(migrateResourceToSupportOverride).toBeCalled(); @@ -79,10 +82,10 @@ test('migration doesnt called when cli-inputs exist', async () => { jest.spyOn(AuthInputState.prototype, 'cliInputFileExists').mockImplementation(() => true); jest.spyOn(AuthInputState.prototype, 'getCLIInputPayload'); const mockContext = { - amplify : { - getImportedAuthProperties : jest.fn().mockReturnValue({ imported : false }) - } - } + amplify: { + getImportedAuthProperties: jest.fn().mockReturnValue({ imported: false }), + }, + }; await checkAuthResourceMigration(mockContext as unknown as $TSContext, 'mockResource'); expect(migrateResourceToSupportOverride).not.toBeCalled(); diff --git a/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/check-for-auth-migration.ts b/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/check-for-auth-migration.ts index 5aa4b966b10..33fbc407077 100644 --- a/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/check-for-auth-migration.ts +++ b/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/check-for-auth-migration.ts @@ -6,14 +6,14 @@ import { migrateResourceToSupportOverride } from './migrate-override-resource'; export const checkAuthResourceMigration = async (context: $TSContext, authName: string) => { // check if its imported auth - const { imported} = context.amplify.getImportedAuthProperties(context); - if(!imported){ + const { imported } = context.amplify.getImportedAuthProperties(context); + if (!imported) { const cliState = new AuthInputState(authName); if (!cliState.cliInputFileExists()) { printer.debug('Cli-inputs.json doesnt exist'); // put spinner here - const isMigrate = await prompter.yesOrNo(`Do you want to migrate this ${authName} to support overrides?`, true); - if (isMigrate) { + const headlessMigrate = context.input.options?.yes || context.input.options?.forcePush || context.input.options?.headless; + if (headlessMigrate || (await prompter.yesOrNo(`Do you want to migrate this ${authName} to support overrides?`, true))) { // generate cli-inputs for migration from parameters.json await migrateResourceToSupportOverride(authName); // fetch cli Inputs again