Skip to content

Commit

Permalink
Resolved issues with removed code
Browse files Browse the repository at this point in the history
  • Loading branch information
MathijsVerbeeck committed Jul 31, 2023
1 parent 155056e commit ac30a5c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
35 changes: 35 additions & 0 deletions src/m365/aad/commands/o365group/o365group-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,41 @@ describe(commands.O365GROUP_GET, () => {
}));
});

it('throws error if retrieved group is not a M365 group', async () => {
const groupId = '1caf7dcd-7e83-4c3a-94f7-932a1299c844';
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/groups/1caf7dcd-7e83-4c3a-94f7-932a1299c844`) {
return {
"id": groupId,
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2017-11-29T03:27:05Z",
"description": "This is the Contoso Finance Group. Please come here and check out the latest news, posts, files, and more.",
"displayName": "Finance",
"groupTypes": [],
"mail": "[email protected]",
"mailEnabled": true,
"mailNickname": "finance",
"onPremisesLastSyncDateTime": null,
"onPremisesProvisioningErrors": [],
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": null,
"proxyAddresses": [
"SMTP:[email protected]"
],
"renewedDateTime": "2017-11-29T03:27:05Z",
"securityEnabled": false,
"visibility": "Public"
};
}

throw 'Invalid request';
});

await assert.rejects(command.action(logger, { options: { id: groupId } }), new CommandError(`Specified group with id '${groupId}' is not a Microsoft 365 group.`));
});

it('handles random API error', async () => {
const errorMessage = 'Something went wrong';
sinon.stub(request, 'get').rejects(new Error(errorMessage));
Expand Down
16 changes: 10 additions & 6 deletions src/m365/aad/commands/o365group/o365group-get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '../../../../cli/Logger';
import GlobalOptions from '../../../../GlobalOptions';
import request from '../../../../request';
import request, { CliRequestOptions } from '../../../../request';
import { validation } from '../../../../utils/validation';
import { aadGroup } from '../../../../utils/aadGroup';
import GraphCommand from '../../../base/GraphCommand';
Expand All @@ -27,11 +27,11 @@ class AadO365GroupGetCommand extends GraphCommand {

constructor() {
super();

this.#initOptions();
this.#initValidators();
}

#initOptions(): void {
this.options.unshift(
{
Expand All @@ -42,14 +42,14 @@ class AadO365GroupGetCommand extends GraphCommand {
}
);
}

#initValidators(): void {
this.validators.push(
async (args: CommandArgs) => {
if (!validation.isValidGuid(args.options.id)) {
return `${args.options.id} is not a valid GUID`;
}

return true;
}
);
Expand All @@ -61,8 +61,12 @@ class AadO365GroupGetCommand extends GraphCommand {
try {
group = await aadGroup.getGroupById(args.options.id);

if (!group.groupTypes!.some(type => type === 'Unified')) {
throw `Specified group with id '${args.options.id}' is not a Microsoft 365 group.`;
}

if (args.options.includeSiteUrl) {
const requestOptions: any = {
const requestOptions: CliRequestOptions = {
url: `${this.resource}/v1.0/groups/${group.id}/drive?$select=webUrl`,
headers: {
accept: 'application/json;odata.metadata=none'
Expand Down

0 comments on commit ac30a5c

Please sign in to comment.