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
Adds the graph schemaextension get cmd #14 #886
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# graph schemaextension get | ||
|
||
Gets information about a Microsoft Graph schema extension | ||
|
||
## Usage | ||
|
||
```sh | ||
graph schemaextension get <options> | ||
``` | ||
|
||
## Options | ||
|
||
Option|Description | ||
------|----------- | ||
`--help`|output usage information | ||
`-i, --id <id>`|The unique identifier for the schema extension definition | ||
`-o, --output [output]`|Output type. `json|text`. Default `text` | ||
`--verbose`|Runs command with verbose logging | ||
`--debug`|Runs command with debug logging | ||
|
||
|
||
!!! important | ||
Before using this command, log in to the Microsoft Graph, using the [graph login](../login.md) command. | ||
|
||
## Remarks | ||
|
||
To get information about a schema extension, you have to first log in to the Microsoft Graph using the [graph login](../login.md) command, eg. `graph login`. | ||
|
||
To get information about a schema extension, you have to specify the unique ID of the schema extension | ||
|
||
## Examples | ||
|
||
Gets information about a schema extension with ID MySchemaExtension | ||
```sh | ||
graph schemaextension get --id MySchemaExtension | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,326 @@ | ||
import commands from '../../commands'; | ||
import Command, { CommandOption, CommandError, CommandValidate } from '../../../../Command'; | ||
import * as sinon from 'sinon'; | ||
import appInsights from '../../../../appInsights'; | ||
import auth from '../../GraphAuth'; | ||
const command: Command = require('./schemaextension-get'); | ||
import * as assert from 'assert'; | ||
import * as request from 'request-promise-native'; | ||
import Utils from '../../../../Utils'; | ||
import { Service } from '../../../../Auth'; | ||
|
||
describe(commands.SCHEMAEXTENSION_GET, () => { | ||
let vorpal: Vorpal; | ||
let log: string[]; | ||
let cmdInstance: any; | ||
let cmdInstanceLogSpy: sinon.SinonSpy; | ||
let trackEvent: any; | ||
let telemetry: any; | ||
|
||
before(() => { | ||
sinon.stub(auth, 'restoreAuth').callsFake(() => Promise.resolve()); | ||
sinon.stub(auth, 'ensureAccessToken').callsFake(() => { return Promise.resolve('ABC'); }); | ||
trackEvent = sinon.stub(appInsights, 'trackEvent').callsFake((t) => { | ||
telemetry = t; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
vorpal = require('../../../../vorpal-init'); | ||
log = []; | ||
cmdInstance = { | ||
log: (msg: string) => { | ||
log.push(msg); | ||
} | ||
}; | ||
cmdInstanceLogSpy = sinon.spy(cmdInstance, 'log'); | ||
auth.service = new Service(); | ||
telemetry = null; | ||
(command as any).items = []; | ||
}); | ||
|
||
afterEach(() => { | ||
Utils.restore([ | ||
vorpal.find, | ||
request.get, | ||
request.post | ||
]); | ||
}); | ||
|
||
after(() => { | ||
Utils.restore([ | ||
appInsights.trackEvent, | ||
auth.ensureAccessToken, | ||
auth.restoreAuth | ||
]); | ||
}); | ||
|
||
it('has correct name', () => { | ||
assert.equal(command.name.startsWith(commands.SCHEMAEXTENSION_GET), true); | ||
}); | ||
|
||
it('has a description', () => { | ||
assert.notEqual(command.description, null); | ||
}); | ||
|
||
it('calls telemetry', (done) => { | ||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ options: {} }, () => { | ||
try { | ||
assert(trackEvent.called); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it('logs correct telemetry event', (done) => { | ||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ options: {} }, () => { | ||
try { | ||
assert.equal(telemetry.name, commands.SCHEMAEXTENSION_GET); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it('aborts when not logged in to Microsoft Graph', (done) => { | ||
auth.service = new Service(); | ||
auth.service.connected = false; | ||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ options: { debug: true } }, (err?: any) => { | ||
try { | ||
assert.equal(JSON.stringify(err), JSON.stringify(new CommandError('Log in to the Microsoft Graph first'))); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it('gets schema extension', (done) => { | ||
sinon.stub(request, 'get').callsFake((opts) => { | ||
if (opts.url.indexOf(`https://graph.microsoft.com/v1.0/schemaExtensions`) === 0) { | ||
return Promise.resolve({ | ||
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity", | ||
"id": "ext6kguklm2_TestSchemaExtension", | ||
"description": "Test Description", | ||
"targetTypes": [ | ||
"Group" | ||
], | ||
"status": "InDevelopment", | ||
"owner": "b07a45b3-f7b7-489b-9269-da6f3f93dff0", | ||
"properties": [ | ||
{ | ||
"name": "MyInt", | ||
"type": "Integer" | ||
}, | ||
{ | ||
"name": "MyString", | ||
"type": "String" | ||
} | ||
] | ||
}); | ||
} | ||
|
||
return Promise.reject('Invalid request'); | ||
}); | ||
|
||
auth.service = new Service(); | ||
auth.service.connected = true; | ||
auth.service.resource = 'https://graph.microsoft.com'; | ||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ | ||
options: { | ||
debug: false, | ||
id: 'ext6kguklm2_TestSchemaExtension', | ||
} | ||
}, () => { | ||
try { | ||
assert(cmdInstanceLogSpy.calledWith({ | ||
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity", | ||
"id": "ext6kguklm2_TestSchemaExtension", | ||
"description": "Test Description", | ||
"targetTypes": [ | ||
"Group" | ||
], | ||
"status": "InDevelopment", | ||
"owner": "b07a45b3-f7b7-489b-9269-da6f3f93dff0", | ||
"properties": [ | ||
{ | ||
"name": "MyInt", | ||
"type": "Integer" | ||
}, | ||
{ | ||
"name": "MyString", | ||
"type": "String" | ||
} | ||
] | ||
})); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it('gets schema extension (debug)', (done) => { | ||
sinon.stub(request, 'get').callsFake((opts) => { | ||
if (opts.url.indexOf(`https://graph.microsoft.com/v1.0/schemaExtensions`) === 0) { | ||
return Promise.resolve({ | ||
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity", | ||
"id": "ext6kguklm2_TestSchemaExtension", | ||
"description": "Test Description", | ||
"targetTypes": [ | ||
"Group" | ||
], | ||
"status": "InDevelopment", | ||
"owner": "b07a45b3-f7b7-489b-9269-da6f3f93dff0", | ||
"properties": [ | ||
{ | ||
"name": "MyInt", | ||
"type": "Integer" | ||
}, | ||
{ | ||
"name": "MyString", | ||
"type": "String" | ||
} | ||
] | ||
}); | ||
} | ||
|
||
return Promise.reject('Invalid request'); | ||
}); | ||
|
||
auth.service = new Service(); | ||
auth.service.connected = true; | ||
auth.service.resource = 'https://graph.microsoft.com'; | ||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ | ||
options: { | ||
debug: true, | ||
id: 'ext6kguklm2_TestSchemaExtension', | ||
} | ||
}, () => { | ||
try { | ||
assert(cmdInstanceLogSpy.calledWith({ | ||
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity", | ||
"id": "ext6kguklm2_TestSchemaExtension", | ||
"description": "Test Description", | ||
"targetTypes": [ | ||
"Group" | ||
], | ||
"status": "InDevelopment", | ||
"owner": "b07a45b3-f7b7-489b-9269-da6f3f93dff0", | ||
"properties": [ | ||
{ | ||
"name": "MyInt", | ||
"type": "Integer" | ||
}, | ||
{ | ||
"name": "MyString", | ||
"type": "String" | ||
} | ||
] | ||
})); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add an extra test to test For example schema not found response.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, the path should be |
||
|
||
it('fails validation if the id is not specified', () => { | ||
const actual = (command.validate() as CommandValidate)({ | ||
options: { | ||
debug: false, | ||
id: null | ||
} | ||
}); | ||
assert.notEqual(actual, true); | ||
}); | ||
|
||
it('passes validation if the id is specified', () => { | ||
const actual = (command.validate() as CommandValidate)({ | ||
options: { | ||
debug: false, | ||
id: 'schemaExtension' | ||
} | ||
}); | ||
assert.equal(actual, true); | ||
}); | ||
|
||
|
||
it('supports debug mode', () => { | ||
const options = (command.options() as CommandOption[]); | ||
let containsOption = false; | ||
options.forEach(o => { | ||
if (o.option === '--debug') { | ||
containsOption = true; | ||
} | ||
}); | ||
assert(containsOption); | ||
}); | ||
|
||
it('has help referring to the right command', () => { | ||
const cmd: any = { | ||
log: (msg: string) => { }, | ||
prompt: () => { }, | ||
helpInformation: () => { } | ||
}; | ||
const find = sinon.stub(vorpal, 'find').callsFake(() => cmd); | ||
cmd.help = command.help(); | ||
cmd.help({}, () => { }); | ||
assert(find.calledWith(commands.SCHEMAEXTENSION_GET)); | ||
}); | ||
|
||
it('has help with examples', () => { | ||
const _log: string[] = []; | ||
const cmd: any = { | ||
log: (msg: string) => { | ||
_log.push(msg); | ||
}, | ||
prompt: () => { }, | ||
helpInformation: () => { } | ||
}; | ||
sinon.stub(vorpal, 'find').callsFake(() => cmd); | ||
cmd.help = command.help(); | ||
cmd.help({}, () => { }); | ||
let containsExamples: boolean = false; | ||
_log.forEach(l => { | ||
if (l && l.indexOf('Examples:') > -1) { | ||
containsExamples = true; | ||
} | ||
}); | ||
Utils.restore(vorpal.find); | ||
assert(containsExamples); | ||
}); | ||
|
||
it('correctly handles lack of valid access token', (done) => { | ||
Utils.restore(auth.ensureAccessToken); | ||
sinon.stub(auth, 'ensureAccessToken').callsFake(() => { return Promise.reject(new Error('Error getting access token')); }); | ||
auth.service = new Service(); | ||
auth.service.connected = true; | ||
auth.service.resource = 'https://graph.microsoft.com'; | ||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ options: { debug: true } }, (err?: any) => { | ||
try { | ||
assert.equal(JSON.stringify(err), JSON.stringify(new CommandError('Error getting access token'))); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove the
request.post
? It is no used at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it should be
schemaextension
notschmeaextension