Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
332 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# todo list list | ||
|
||
Returns a list of Microsoft To Do task lists | ||
|
||
## Usage | ||
|
||
```sh | ||
todo list list [options] | ||
``` | ||
|
||
## Options | ||
|
||
Option|Description | ||
------|----------- | ||
`--help`|output usage information | ||
`--query [query]`|JMESPath query string. See http://jmespath.org/ for more information and examples | ||
`-o, --output [output]`|Output type. `json,text`. Default `text` | ||
`--pretty`|Prettifies `json` output | ||
`--verbose`|Runs command with verbose logging | ||
`--debug`|Runs command with debug logging | ||
|
||
## Examples | ||
|
||
Get the list of Microsoft To Do task lists | ||
|
||
```sh | ||
todo list list | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const prefix: string = 'todo'; | ||
|
||
export default { | ||
LIST_LIST: `${prefix} list list` | ||
}; |
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,238 @@ | ||
import commands from '../../commands'; | ||
import Command, { CommandOption } from '../../../../Command'; | ||
import * as sinon from 'sinon'; | ||
import appInsights from '../../../../appInsights'; | ||
import auth from '../../../../Auth'; | ||
const command: Command = require('./list-list'); | ||
import * as assert from 'assert'; | ||
import request from '../../../../request'; | ||
import Utils from '../../../../Utils'; | ||
|
||
describe(commands.LIST_LIST, () => { | ||
let vorpal: Vorpal; | ||
let log: string[]; | ||
let cmdInstance: any; | ||
|
||
before(() => { | ||
sinon.stub(auth, 'restoreAuth').callsFake(() => Promise.resolve()); | ||
sinon.stub(appInsights, 'trackEvent').callsFake(() => { }); | ||
auth.service.connected = true; | ||
}); | ||
|
||
beforeEach(() => { | ||
vorpal = require('../../../../vorpal-init'); | ||
log = []; | ||
cmdInstance = { | ||
commandWrapper: { | ||
command: command.name | ||
}, | ||
action: command.action(), | ||
log: (msg: string) => { | ||
log.push(msg); | ||
} | ||
}; | ||
(command as any).items = []; | ||
}); | ||
|
||
afterEach(() => { | ||
Utils.restore([ | ||
vorpal.find, | ||
request.get | ||
]); | ||
}); | ||
|
||
after(() => { | ||
Utils.restore([ | ||
auth.restoreAuth, | ||
appInsights.trackEvent | ||
]); | ||
auth.service.connected = false; | ||
}); | ||
|
||
it('has correct name', () => { | ||
assert.equal(command.name.startsWith(commands.LIST_LIST), true); | ||
}); | ||
|
||
it('has a description', () => { | ||
assert.notEqual(command.description, null); | ||
}); | ||
|
||
it('lists To Do task lists', (done) => { | ||
sinon.stub(request, 'get').callsFake((opts) => { | ||
if (opts.url === `https://graph.microsoft.com/beta/me/todo/lists`) { | ||
return Promise.resolve({ | ||
"@odata.context": "https://graph.microsoft.com/beta/$metadata#lists", | ||
"value": [ | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrpQ==\"", | ||
"displayName": "Tasks", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "defaultList", | ||
"id": "AQMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAADkNZdo3x_lUma2pLT-Ge2rgEAm1fdwWoFiE2YS9yegTKoYwAAAgESAAAA" | ||
}, | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrpw==\"", | ||
"displayName": "Foo", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "none", | ||
"id": "AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIeAAA=" | ||
}, | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrqQ==\"", | ||
"displayName": "Bar", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "none", | ||
"id": "AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIjAAA=" | ||
} | ||
] | ||
}); | ||
} | ||
|
||
return Promise.reject('Invalid request'); | ||
}); | ||
|
||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ | ||
options: { | ||
debug: false | ||
} | ||
}, () => { | ||
try { | ||
const actual = JSON.stringify(log[log.length - 1]); | ||
const expected = JSON.stringify([ | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrpQ==\"", | ||
"displayName": "Tasks", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "defaultList", | ||
"id": "AQMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAADkNZdo3x_lUma2pLT-Ge2rgEAm1fdwWoFiE2YS9yegTKoYwAAAgESAAAA" | ||
}, | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrpw==\"", | ||
"displayName": "Foo", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "none", | ||
"id": "AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIeAAA=" | ||
}, | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrqQ==\"", | ||
"displayName": "Bar", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "none", | ||
"id": "AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIjAAA=" | ||
} | ||
]); | ||
assert.equal(actual, expected); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it('lists To Do task lists (verbose)', (done) => { | ||
sinon.stub(request, 'get').callsFake((opts) => { | ||
if (opts.url === `https://graph.microsoft.com/beta/me/todo/lists`) { | ||
return Promise.resolve({ | ||
"@odata.context": "https://graph.microsoft.com/beta/$metadata#lists", | ||
"value": [ | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrpQ==\"", | ||
"displayName": "Tasks", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "defaultList", | ||
"id": "AQMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAADkNZdo3x_lUma2pLT-Ge2rgEAm1fdwWoFiE2YS9yegTKoYwAAAgESAAAA" | ||
}, | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrpw==\"", | ||
"displayName": "Foo", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "none", | ||
"id": "AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIeAAA=" | ||
}, | ||
{ | ||
"@odata.etag": "W/\"m1fdwWoFiE2YS9yegTKoYwAA/hqrqQ==\"", | ||
"displayName": "Bar", | ||
"isOwner": true, | ||
"isShared": false, | ||
"wellknownListName": "none", | ||
"id": "AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIjAAA=" | ||
} | ||
] | ||
}); | ||
} | ||
|
||
return Promise.reject('Invalid request'); | ||
}); | ||
|
||
cmdInstance.action = command.action(); | ||
cmdInstance.action({ | ||
options: { | ||
debug: false, | ||
verbose: true | ||
} | ||
}, () => { | ||
try { | ||
assert(log[log.length - 1].indexOf('DONE') > -1); | ||
done(); | ||
} | ||
catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
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.LIST_LIST)); | ||
}); | ||
|
||
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); | ||
}); | ||
}); |
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,58 @@ | ||
import commands from '../../commands'; | ||
import request from '../../../../request'; | ||
import GlobalOptions from '../../../../GlobalOptions'; | ||
import GraphCommand from '../../../base/GraphCommand'; | ||
|
||
const vorpal: Vorpal = require('../../../../vorpal-init'); | ||
|
||
interface CommandArgs { | ||
options: Options; | ||
} | ||
|
||
interface Options extends GlobalOptions { } | ||
|
||
class TodoListListCommand extends GraphCommand { | ||
public get name(): string { | ||
return `${commands.LIST_LIST}`; | ||
} | ||
|
||
public get description(): string { | ||
return 'Returns a list of Microsoft To Do task lists'; | ||
} | ||
|
||
public commandAction(cmd: CommandInstance, args: CommandArgs, cb: (err?: any) => void): void { | ||
|
||
const requestOptions: any = { | ||
url: `${this.resource}/beta/me/todo/lists`, | ||
headers: { | ||
accept: 'application/json;odata.metadata=none', | ||
'content-type': 'application/json' | ||
}, | ||
json: true | ||
}; | ||
|
||
request | ||
.get(requestOptions) | ||
.then((res: any): void => { | ||
cmd.log(res.value); | ||
|
||
if (this.verbose) { | ||
cmd.log(vorpal.chalk.green('DONE')); | ||
} | ||
|
||
cb(); | ||
}, (err: any) => this.handleRejectedODataJsonPromise(err, cmd, cb)); | ||
} | ||
|
||
public commandHelp(args: {}, log: (help: string) => void): void { | ||
log(vorpal.find(this.name).helpInformation()); | ||
log( | ||
` | ||
Examples: | ||
Get the list of Microsoft To Do task lists | ||
`); | ||
} | ||
} | ||
|
||
module.exports = new TodoListListCommand(); |