-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new 'people profilecardproperty list' command. Closes: #5618
- Loading branch information
Showing
7 changed files
with
381 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
108 changes: 108 additions & 0 deletions
108
docs/docs/cmd/tenant/people/people-profilecardproperty-list.mdx
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,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> |
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
182 changes: 182 additions & 0 deletions
182
src/m365/tenant/commands/people/people-profilecardproperty-list.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,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)); | ||
}); | ||
}); |
Oops, something went wrong.