From 44351efd675e8599bfbfc02d61a022fcb69e169e Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 8 Nov 2021 10:58:31 -0800 Subject: [PATCH] fix: headless migrate auth --- .../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