Skip to content

Commit

Permalink
Adds additional command
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-it committed Jul 18, 2023
1 parent e937bf4 commit 7e613d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,41 @@ describe(commands.EXTERNALCONNECTION_REMOVE, () => {
}
} as any), new CommandError("Multiple external connections with name My HR found. Please disambiguate (IDs): fabrikamhr, contosohr"));
});

it('handles selecting single result when external connections with the specified name found and cli is set to prompt', async () => {
let removeRequestIssued = false;

sinonUtil.restore(request.get);
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/external/connections?$filter=name eq 'My%20HR'&$select=id`) {
return {
value: [
{
"id": "fabrikamhr"
},
{
"id": "contosohr"
}
]
};
}

throw "Invalid request";
});

sinon.stub(Cli, 'handleMultipleResultsFound').resolves({
"id": "contosohr"
});

sinon.stub(request, 'delete').callsFake(async (opts: any) => {
if (opts.url === 'https://graph.microsoft.com/v1.0/external/connections/contosohr') {
removeRequestIssued = true;
return;
}
throw '';
});

await command.action(logger, { options: { name: "My HR", confirm: true } });
assert(removeRequestIssued);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class SearchExternalConnectionRemoveCommand extends GraphCommand {
throw `The specified connection does not exist in Microsoft Search`;
}

throw `Multiple external connections with name ${args.options.name} found. Please disambiguate (IDs): ${res.value.map(x => x.id).join(', ')}`;
const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
return ((await Cli.handleMultipleResultsFound(`Multiple external connections with name ${args.options.name} found. Choose the correct ID:`, `Multiple external connections with name ${args.options.name} found. Please disambiguate (IDs): ${res.value.map(x => x.id).join(', ')}`, resultAsKeyValuePair)) as { id: string }).id;
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
Expand Down

0 comments on commit 7e613d0

Please sign in to comment.