Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command: viva engage community get. Closes #5754 #5920

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const dictionary = [
'client',
'comm',
'command',
'community',
'containertype',
'content',
'conversation',
Expand Down
94 changes: 94 additions & 0 deletions docs/docs/cmd/viva/engage/engage-community-get.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# viva engage community get

Gets information of a Viva Engage community.

## Usage

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

## Options

```md definition-list
`-i, --id <id>`
: The unique identifier of the community.
```

<Global />

## Remarks

:::warning

This command is based on an API that is currently in preview and is subject to change once the API reached general availability.

:::

## Examples

Get a specific community by ID.

```sh
m365 viva engage community get --id eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiI0Mjg1NzkwNjE3NyJ9
```

## Response

<Tabs>
<TabItem value="JSON">

```json
{
"id": "eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ",
"displayName": "New Employee Onboarding",
"description": "New Employee Onboarding",
"privacy": "public",
"groupId": "54dda9b2-2df1-4ce8-ae1e-b400956b5b34"
}
```

</TabItem>
<TabItem value="Text">

```text
description: New Employee Onboarding
displayName: New Employee Onboarding
groupId : 54dda9b2-2df1-4ce8-ae1e-b400956b5b34
id : eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ
privacy : public
```

</TabItem>
<TabItem value="CSV">

```csv
id,displayName,description,privacy,groupId
eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ,New Employee Onboarding,New Employee Onboarding,public,54dda9b2-2df1-4ce8-ae1e-b400956b5b34
```

</TabItem>
<TabItem value="Markdown">

```md
# viva engage community get --id "eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ"

Date: 14/03/2024

## New Employee Onboarding (eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ)

Property | Value
---------|-------
id | eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ
displayName | New Employee Onboarding
description | New Employee Onboarding
privacy | public
groupId | 54dda9b2-2df1-4ce8-ae1e-b400956b5b34
```

</TabItem>
</Tabs>
5 changes: 5 additions & 0 deletions docs/src/config/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4286,6 +4286,11 @@ const sidebars: SidebarsConfig = {
label: 'engage search',
id: 'cmd/viva/engage/engage-search'
},
{
type: 'doc',
label: 'engage community get',
id: 'cmd/viva/engage/engage-community-get'
},
{
type: 'doc',
label: 'engage group 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 @@ -2,6 +2,7 @@ const prefix: string = 'viva';

export default {
CONNECTIONS_APP_CREATE: `${prefix} connections app create`,
ENGAGE_COMMUNITY_GET: `${prefix} engage community get`,
ENGAGE_GROUP_LIST: `${prefix} engage group list`,
ENGAGE_GROUP_USER_ADD: `${prefix} engage group user add`,
ENGAGE_GROUP_USER_REMOVE: `${prefix} engage group user remove`,
Expand Down
96 changes: 96 additions & 0 deletions src/m365/viva/commands/engage/engage-community-get.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

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-get.js';

describe(commands.ENGAGE_COMMUNITY_GET, () => {
let log: string[];
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;

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;
});

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

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

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

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

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

it('correctly handles error', async () => {
const errorMessage = 'Bad request.';
sinon.stub(request, 'get').rejects({
error: {
message: errorMessage
}
});

await assert.rejects(command.action(logger, { options: { id: 'invalid', verbose: true } } as any),
new CommandError(errorMessage));
});

it('gets community by id', async () => {
const communityId = 'eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ';
const response = {
id: communityId,
displayName: "New Employee Onboarding",
description: "New Employee Onboarding",
privacy: "public",
groupId: "54dda9b2-2df1-4ce8-ae1e-b400956b5b34"
};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/beta/employeeExperience/communities/${communityId}`) {
return response;
}

throw 'Invalid Request';
});

await command.action(logger, { options: { id: communityId } } as any);
assert.deepStrictEqual(loggerLogSpy.lastCall.args[0], response);
});
});
65 changes: 65 additions & 0 deletions src/m365/viva/commands/engage/engage-community-get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import GlobalOptions from '../../../../GlobalOptions.js';
import { Logger } from '../../../../cli/Logger.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
import request, { CliRequestOptions } from '../../../../request.js';

interface CommandArgs {
options: Options;
}

interface Options extends GlobalOptions {
id: string;
}

class VivaEngageCommunityGetCommand extends GraphCommand {
public get name(): string {
return commands.ENGAGE_COMMUNITY_GET;
}

public get description(): string {
return 'Gets information of a Viva Engage community';
}

constructor() {
super();

this.#initOptions();
Saurabh7019 marked this conversation as resolved.
Show resolved Hide resolved
this.#initTypes();
}

#initOptions(): void {
this.options.unshift(
{ option: '-i, --id <id>' }
);
}

#initTypes(): void {
this.types.string.push('id');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
logger.logToStderr(`Getting the information of Viva Engage community with id '${args.options.id}'...`);
}

const requestOptions: CliRequestOptions = {
url: `${this.resource}/beta/employeeExperience/communities/${args.options.id}`,
headers: {
accept: 'application/json;odata.metadata=none'
},
responseType: 'json'
};

try {
const res = await request.get<any>(requestOptions);

await logger.log(res);
}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
}
}
}

export default new VivaEngageCommunityGetCommand();