Skip to content

Commit

Permalink
fix: headless migrate auth (aws-amplify#8735)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu committed Nov 10, 2021
1 parent 072b87b commit 3510899
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3510899

Please sign in to comment.