Skip to content

Commit

Permalink
Adds new 'people profilecardproperty list' command. Closes: #5618
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-it committed Nov 4, 2023
1 parent ba486fa commit 290bd7c
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const dictionary = [
'audit',
'bin',
'builder',
'card',
'catalog',
'checklist',
'client',
Expand Down Expand Up @@ -67,6 +68,7 @@ const dictionary = [
'permission',
'place',
'policy',
'profile',
'property',
'records',
'recycle',
Expand Down
108 changes: 108 additions & 0 deletions docs/docs/cmd/tenant/people/people-profilecardproperty-list.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# tenant people profilecardproperty list

Lists all profile card properties

## Usage

```sh
m365 tenant people profilecardproperty list [options]
```

## Options

<Global />

## Remarks

:::info

To use this command you must be either **Tenant Administrator** or **Global Administrator**.

:::

## Examples

Lists all profile card properties

```sh

```sh
m365 tenant people profilecardproperty list
```

## Response

<Tabs>
<TabItem value="JSON">

```json
{
"value": [
{
"directoryPropertyName": "customAttribute1",
"annotations": [
{
"displayName": "Cost center",
"localizations": [
{
"languageTag": "de",
"displayName": "Kostenstelle"
}
]
}
]
},
{
"directoryPropertyName": "Alias",
"annotations": []
}
]
}
```

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

```text
directoryPropertyName displayName displayName de
--------------------- -------------- --------------
customAttribute1 Cost center Kostenstelle
Alias
```

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

```csv
directoryPropertyName,displayName,displayName de
customAttribute1,Cost center,Kostenstelle
Alias,,
```

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

```md
# tenant people profilecardproperty list
Date: 11/4/2023
## Cost center
Property | Value
---------|-------
directoryPropertyName | customAttribute1
displayName | Cost center
displayName de | Kostenstelle
Property | Value
---------|-------
directoryPropertyName | Alias
```

</TabItem>
</Tabs>
9 changes: 9 additions & 0 deletions docs/src/config/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ const sidebars = {
}
]
},
{
people: [
{
type: 'doc',
label: 'people profilecardproperty list',
id: 'cmd/tenant/people/people-profilecardproperty-list'
}
]
},
{
report: [
{
Expand Down
1 change: 1 addition & 0 deletions src/m365/tenant/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const prefix: string = 'tenant';
export default {
ID_GET: `${prefix} id get`,
INFO_GET: `${prefix} info get`,
PEOPLE_PROFILECARDPROPERTY_LIST: `${prefix} people profilecardproperty list`,
REPORT_ACTIVEUSERCOUNTS: `${prefix} report activeusercounts`,
REPORT_ACTIVEUSERDETAIL: `${prefix} report activeuserdetail`,
REPORT_OFFICE365ACTIVATIONCOUNTS: `${prefix} report office365activationcounts`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
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 './people-profilecardproperty-list.js';

describe(commands.PEOPLE_PROFILECARDPROPERTY_LIST, () => {
const profileCardPropertyName1 = 'customAttribute1';
const profileCardPropertyName2 = 'customAttribute2';

//#region Mocked responses
const response =
{
value: [
{
directoryPropertyName: profileCardPropertyName1,
annotations: [
{
displayName: 'Department',
localizations: [
{
languageTag: 'de',
displayName: 'Abteilung'
},
{
languageTag: 'pl',
displayName: 'Departament'
}
]
}
]
},
{
directoryPropertyName: "Alias",
annotations: []
},
{
directoryPropertyName: profileCardPropertyName2,
annotations: [
{
displayName: 'Cost center',
localizations: [
{
languageTag: 'de',
displayName: 'Kostenstelle'
}
]
}
]
},
{
directoryPropertyName: profileCardPropertyName2,
annotations: [
{
displayName: 'Cost center',
localizations: [
{
languageTag: 'de',
displayName: 'Kostenstelle'
}
]
}
]
}
]
};
//#endregion

let log: any[];
let loggerLogSpy: sinon.SinonSpy;
let logger: Logger;

before(() => {
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.service.connected = 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.service.connected = false;
});

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

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

it('lists profile card properties', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/admin/people/profileCardProperties`) {
return response;
}

throw 'Invalid Request';
});

await command.action(logger, { options: { verbose: true } });
assert(loggerLogSpy.calledOnceWith(response));
});

it('lists profile card properties information for other than json output', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/admin/people/profileCardProperties`) {
return response;
}

throw 'Invalid Request';
});

const textOutput = [
{
directoryPropertyName: profileCardPropertyName1,
displayName: response.value[0].annotations[0].displayName,
['displayName ' + response.value[0].annotations[0].localizations[0].languageTag]: response.value[0].annotations[0].localizations[0].displayName,
['displayName ' + response.value[0].annotations[0].localizations[1].languageTag]: response.value[0].annotations[0].localizations[1].displayName
},
{
directoryPropertyName: "Alias"
},
{
directoryPropertyName: profileCardPropertyName2,
displayName: response.value[2].annotations[0].displayName,
['displayName ' + response.value[2].annotations[0].localizations[0].languageTag]: response.value[2].annotations[0].localizations[0].displayName
},
{
directoryPropertyName: profileCardPropertyName2,
displayName: response.value[3].annotations[0].displayName,
['displayName ' + response.value[3].annotations[0].localizations[0].languageTag]: response.value[3].annotations[0].localizations[0].displayName
}
];

await command.action(logger, { options: { output: 'text' } });
assert(loggerLogSpy.calledOnceWith(textOutput));
});

it('handles unexpected API error', async () => {
const errorMessage = 'Something went wrong';
sinon.stub(request, 'get').rejects({
error: {
message: errorMessage
}
});

await assert.rejects(command.action(logger, { options: { debug: true } }),
new CommandError(errorMessage));
});
});
Loading

0 comments on commit 290bd7c

Please sign in to comment.