Skip to content

Commit

Permalink
Adds command 'viva engage community set'. Closes #6279
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinM85 authored and Adam-it committed Nov 15, 2024
1 parent d492cab commit f80ea79
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 1 deletion.
61 changes: 61 additions & 0 deletions docs/docs/cmd/viva/engage/engage-community-set.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# viva engage community set

Updates an existing Viva Engage community

## Usage

```sh
m365 viva engage community set [options]
```

## Options

```md definition-list
`-i, --id [id]`
: The id of the community. Specify either `id`, `displayName` or `entraGroupId`, but not multiple.

`-d, --displayName [displayName]`
: The name of the community. Specify either `id`, `displayName` or `entraGroupId`, but not multiple.

`--entraGroupId [entraGroupId]`
: The id of the Microsoft Entra group associated with the community. Specify either `id`, `displayName` or `entraGroupId`, but not multiple.

`--newDisplayName [newDisplayName]`
: New name for the community. The maximum length is 255 characters.

`--description [description]`
: The description of the community. The maximum length is 1024 characters.

`--privacy [privacy]`
: Defines the privacy level of the community. The possible values are: `public`, and `private`.
```

<Global />

## Examples

Update info about the community specified by id

```sh
m365 viva engage community set --id eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiI0NzY5MTM1ODIwOSJ9 --newDisplayName 'Developers' --description 'Community for all devs' --privacy public
```

Update info about the community specified by name

```sh
m365 viva engage community set --displayName 'Developrs' --newDisplayName 'Developers'
```

Update info about the community specified by Entra group id

```sh
m365 viva engage community set --entraGroupId '0bed8b86-5026-4a93-ac7d-56750cc099f1' --newDisplayName 'Developers'
```

## Response

The command won't return a response on success.
5 changes: 5 additions & 0 deletions docs/src/config/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4518,6 +4518,11 @@ const sidebars: SidebarsConfig = {
label: 'engage community list',
id: 'cmd/viva/engage/engage-community-list'
},
{
type: 'doc',
label: 'engage community set',
id: 'cmd/viva/engage/engage-community-set'
},
{
type: 'doc',
label: 'engage community user list',
Expand Down
1 change: 1 addition & 0 deletions src/m365/viva/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
ENGAGE_COMMUNITY_ADD: `${prefix} engage community add`,
ENGAGE_COMMUNITY_GET: `${prefix} engage community get`,
ENGAGE_COMMUNITY_LIST: `${prefix} engage community list`,
ENGAGE_COMMUNITY_SET: `${prefix} engage community set`,
ENGAGE_COMMUNITY_USER_LIST: `${prefix} engage community user list`,
ENGAGE_GROUP_LIST: `${prefix} engage group list`,
ENGAGE_GROUP_USER_ADD: `${prefix} engage group user add`,
Expand Down
177 changes: 177 additions & 0 deletions src/m365/viva/commands/engage/engage-community-set.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import assert from 'assert';
import sinon from 'sinon';
import auth from '../../../../Auth.js';
import { Logger } from '../../../../cli/Logger.js';
import { CommandError } from '../../../../Command.js';
import request from '../../../../request.js';
import { telemetry } from '../../../../telemetry.js';
import { pid } from '../../../../utils/pid.js';
import { session } from '../../../../utils/session.js';
import { sinonUtil } from '../../../../utils/sinonUtil.js';
import commands from '../../commands.js';
import command from './engage-community-set.js';
import { CommandInfo } from '../../../../cli/CommandInfo.js';
import { vivaEngage } from '../../../../utils/vivaEngage.js';
import { cli } from '../../../../cli/cli.js';

describe(commands.ENGAGE_COMMUNITY_SET, () => {
const communityId = 'eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiI0NzY5MTM1ODIwOSJ9';
const displayName = 'Software Engineers';
const entraGroupId = '0bed8b86-5026-4a93-ac7d-56750cc099f1';
let log: string[];
let logger: Logger;
let commandInfo: CommandInfo;

before(() => {
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.connection.active = true;
commandInfo = cli.getCommandInfo(command);
});

beforeEach(() => {
log = [];
logger = {
log: async (msg: string) => {
log.push(msg);
},
logRaw: async (msg: string) => {
log.push(msg);
},
logToStderr: async (msg: string) => {
log.push(msg);
}
};
});

afterEach(() => {
sinonUtil.restore([
request.patch
]);
});

after(() => {
sinon.restore();
auth.connection.active = false;
});

it('has correct name', () => {
assert.strictEqual(command.name, commands.ENGAGE_COMMUNITY_SET);
});

it('has a description', () => {
assert.notStrictEqual(command.description, null);
});

it('passes validation when id is specified', async () => {
const actual = await command.validate({ options: { id: communityId, description: 'Community for all devs' } }, commandInfo);
assert.strictEqual(actual, true);
});

it('passes validation when displayName is specified', async () => {
const actual = await command.validate({ options: { displayName: 'Software Engineers', description: 'Community for all devs' } }, commandInfo);
assert.strictEqual(actual, true);
});

it('passes validation when entraGroupId is specified', async () => {
const actual = await command.validate({ options: { entraGroupId: '0bed8b86-5026-4a93-ac7d-56750cc099f1', description: 'Community for all devs' } }, commandInfo);
assert.strictEqual(actual, true);
});

it('fails validation when newDisplayName, description or privacy is not specified', async () => {
const actual = await command.validate({ options: { displayName: 'Software Engineers' } }, commandInfo);
assert.notStrictEqual(actual, true);
});

it('fails validation if newDisplayName is more than 255 characters', async () => {
const actual = await command.validate({
options: {
id: communityId,
newDisplayName: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries."
}
}, commandInfo);
assert.notStrictEqual(actual, true);
});

it('fails validation if description is more than 1024 characters', async () => {
const actual = await command.validate({
options: {
displayName: 'Software engineers',
description: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text.All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet.`
}
}, commandInfo);
assert.notStrictEqual(actual, true);
});

it('fails validation when invalid privacy option is provided', async () => {
const actual = await command.validate({
options: {
displayName: 'Software engineers',
privacy: 'invalid'
}
}, commandInfo);
assert.notStrictEqual(actual, true);
});

it('fails validation when entraGroupId is not a valid GUID', async () => {
const actual = await command.validate({ options: { entraGroupId: 'foo', description: 'Community for all devs' } }, commandInfo);
assert.notStrictEqual(actual, true);
});

it('updates info about a community specified by id', async () => {
const patchRequestStub = sinon.stub(request, 'patch').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/employeeExperience/communities/${communityId}`) {
return;
}

throw 'Invalid request';
});

await command.action(logger, { options: { id: communityId, newDisplayName: 'Software Engineers', verbose: true } });
assert(patchRequestStub.called);
});

it('updates info about a community specified by displayName', async () => {
sinon.stub(vivaEngage, 'getCommunityByDisplayName').resolves({ id: communityId });
const patchRequestStub = sinon.stub(request, 'patch').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/employeeExperience/communities/${communityId}`) {
return;
}

throw 'Invalid request';
});

await command.action(logger, { options: { displayName: displayName, description: 'Community for all devs', privacy: 'Public', verbose: true } });
assert(patchRequestStub.called);
});

it('updates info about a community specified by entraGroupId', async () => {
sinon.stub(vivaEngage, 'getCommunityByEntraGroupId').resolves({ id: communityId });
const patchRequestStub = sinon.stub(request, 'patch').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/employeeExperience/communities/${communityId}`) {
return;
}

throw 'Invalid request';
});

await command.action(logger, { options: { entraGroupId: entraGroupId, description: 'Community for all devs', privacy: 'Public', verbose: true } });
assert(patchRequestStub.called);
});

it('handles error when updating Viva Engage community failed', async () => {
sinon.stub(request, 'patch').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/employeeExperience/communities/${communityId}`) {
throw { error: { message: 'An error has occurred' } };
}
throw `Invalid request`;
});

await assert.rejects(
command.action(logger, { options: { id: communityId } } as any),
new CommandError('An error has occurred')
);
});
});
Loading

0 comments on commit f80ea79

Please sign in to comment.