-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command: viva engage community get. Closes #5754
- Loading branch information
1 parent
d874bca
commit fc53ab5
Showing
6 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ const dictionary = [ | |
'client', | ||
'comm', | ||
'command', | ||
'community', | ||
'content', | ||
'conversation', | ||
'custom', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
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 | ||
`--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. | ||
|
||
In order to use this command, you need to grant the Azure AD application used by the CLI for Microsoft 365 the permission to the Viva Engage API. To do this, execute the `cli consent --service VivaEngage` command. | ||
|
||
::: | ||
|
||
## 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/m365/viva/commands/engage/engage-community-get.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
|
||
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').callsFake(() => Promise.resolve()); | ||
sinon.stub(telemetry, 'trackEvent').callsFake(() => { }); | ||
sinon.stub(pid, 'getProcessName').callsFake(() => ''); | ||
sinon.stub(session, 'getId').callsFake(() => ''); | ||
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.startsWith(commands.ENGAGE_COMMUNITY_GET), true); | ||
}); | ||
|
||
it('has a description', () => { | ||
assert.notStrictEqual(command.description, null); | ||
}); | ||
|
||
it('correctly handles error', async () => { | ||
sinon.stub(request, 'get').callsFake(async (opts) => { | ||
const url: string = opts.url as string; | ||
|
||
if (url === 'https://graph.microsoft.com/beta/employeeExperience/communities/invalid') { | ||
throw { | ||
"error": { | ||
"code": "badRequest", | ||
"message": "Bad request.", | ||
"innerError": { | ||
"date": "2024-03-14T10:59:12", | ||
"request-id": "ac728cbd-0978-473b-ab4d-63a51312004a", | ||
"client-request-id": "6302be7a-9539-138a-26cc-eaa41245ce41" | ||
} | ||
} | ||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await assert.rejects(() => command.action(logger, { | ||
options: { | ||
id: 'invalid', | ||
verbose: true | ||
} | ||
}), new CommandError(`Bad request.`)); | ||
}); | ||
|
||
it('gets community by id', async () => { | ||
sinon.stub(request, 'get').callsFake((opts) => { | ||
const url: string = opts.url as string; | ||
|
||
if (url === 'https://graph.microsoft.com/beta/employeeExperience/communities/eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ') { | ||
return Promise.resolve( | ||
{ | ||
"id": "eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ", | ||
"displayName": "New Employee Onboarding", | ||
"description": "New Employee Onboarding", | ||
"privacy": "public", | ||
"groupId": "54dda9b2-2df1-4ce8-ae1e-b400956b5b34" | ||
} | ||
); | ||
} | ||
|
||
return Promise.reject('Invalid request'); | ||
}); | ||
|
||
await command.action(logger, { options: { id: 'eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ' } } as any); | ||
assert.strictEqual(loggerLogSpy.lastCall.args[0].id, 'eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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.#initTelemetry(); | ||
this.#initOptions(); | ||
} | ||
|
||
#initTelemetry(): void { | ||
this.telemetry.push((args: CommandArgs) => { | ||
Object.assign(this.telemetryProperties, { | ||
id: args.options.id !== undefined | ||
}); | ||
}); | ||
} | ||
|
||
#initOptions(): void { | ||
this.options.unshift( | ||
{ option: '-i, --id <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', | ||
'content-type': 'application/json;odata=nometadata' | ||
}, | ||
responseType: 'json' | ||
}; | ||
|
||
try { | ||
const res: any = await request.get(requestOptions); | ||
|
||
await logger.log(res); | ||
} | ||
catch (err: any) { | ||
this.handleRejectedODataJsonPromise(err); | ||
} | ||
} | ||
} | ||
|
||
export default new VivaEngageCommunityGetCommand(); |