Skip to content
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

Refactor codebase to async/await - todo task get until yammer message add, Closes #5116 #5138

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/m365/todo/commands/task/task-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ describe(commands.TASK_GET, () => {

before(() => {
cli = Cli.getInstance();
sinon.stub(auth, 'restoreAuth').callsFake(() => Promise.resolve());
sinon.stub(telemetry, 'trackEvent').callsFake(() => { });
sinon.stub(pid, 'getProcessName').callsFake(() => '');
sinon.stub(session, 'getId').callsFake(() => '');
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.service.connected = true;
commandInfo = Cli.getCommandInfo(command);
});
Expand Down Expand Up @@ -81,7 +81,7 @@ describe(commands.TASK_GET, () => {
});

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

it('has a description', () => {
Expand Down
36 changes: 18 additions & 18 deletions src/m365/todo/commands/task/task-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe(commands.TASK_LIST, () => {

before(() => {
cli = Cli.getInstance();
sinon.stub(auth, 'restoreAuth').callsFake(() => Promise.resolve());
sinon.stub(telemetry, 'trackEvent').callsFake(() => { });
sinon.stub(pid, 'getProcessName').callsFake(() => '');
sinon.stub(session, 'getId').callsFake(() => '');
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.service.connected = true;
commandInfo = Cli.getCommandInfo(command);
});
Expand Down Expand Up @@ -61,7 +61,7 @@ describe(commands.TASK_LIST, () => {
});

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

it('has a description', () => {
Expand Down Expand Up @@ -91,11 +91,11 @@ describe(commands.TASK_LIST, () => {
});

it('fails to get ToDo Task list when the specified task list does not exist', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf(`/me/todo/lists?$filter=displayName eq '`) > -1) {
return Promise.resolve({ value: [] });
return { value: [] };
}
return Promise.reject('The specified task list does not exist');
throw 'The specified task list does not exist';
});

await assert.rejects(command.action(logger, { options: { listName: 'Tasks List' } } as any), new CommandError('The specified task list does not exist'));
Expand All @@ -120,9 +120,9 @@ describe(commands.TASK_LIST, () => {
});

it('lists To Do tasks using listId in JSON output mode', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf(`/tasks`) > -1) {
return Promise.resolve({
return {
value: [
{
"importance": "normal",
Expand Down Expand Up @@ -151,10 +151,10 @@ describe(commands.TASK_LIST, () => {
}
}
]
});
};
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});

await command.action(logger, {
Expand Down Expand Up @@ -196,9 +196,9 @@ describe(commands.TASK_LIST, () => {
});

it('lists To Do tasks using listName', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf(`/me/todo/lists?$filter=displayName eq '`) > -1) {
return Promise.resolve({
return {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('e1251b10-1ba4-49e3-b35a-933e3f21772b')/todo/lists",
"value": [
{
Expand All @@ -210,11 +210,11 @@ describe(commands.TASK_LIST, () => {
"id": "AQMkAGYzNjMxYTU4LTJjZjYtNDlhMi1iMzQ2LWVmMTU3YmUzOGM5MAAuAAADMN-7V4K8g0q_adetip1DygEAxMBBaLl1lk_dAn8KkjfXKQABF-BAgwAAAA=="
}
]
});
};
}

if ((opts.url as string).indexOf(`/tasks`) > -1) {
return Promise.resolve({
return {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('e1251b10-1ba4-49e3-b35a-933e3f21772b')/todo/lists('AQMkAGYzNjMxYTU4LTJjZjYtNDlhMi1iMzQ2LWVmMTU3YmUzOGM5MAAuAAADMN-7V4K8g0q_adetip1DygEAxMBBaLl1lk_dAn8KkjfXKQABF-BAgwAAAA%3D%3D')/tasks",
"value": [
{
Expand All @@ -232,10 +232,10 @@ describe(commands.TASK_LIST, () => {
"lastModifiedDateTime": "2020-11-01T17:13:13.1037095Z"
}
]
});
};
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});

await command.action(logger, {
Expand Down
18 changes: 8 additions & 10 deletions src/m365/todo/commands/task/task-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class TodoTaskListCommand extends GraphCommand {
this.optionSets.push({ options: ['listId', 'listName'] });
}

private getTodoListId(args: CommandArgs): Promise<string> {
private async getTodoListId(args: CommandArgs): Promise<string> {
if (args.options.listId) {
return Promise.resolve(args.options.listId);
return args.options.listId;
}

const requestOptions: any = {
Expand All @@ -74,16 +74,14 @@ class TodoTaskListCommand extends GraphCommand {
responseType: 'json'
};

return request.get<{ value: [{ id: string }] }>(requestOptions)
.then(response => {
const taskList: { id: string } | undefined = response.value[0];
const response: any = await request.get<{ value: [{ id: string }] }>(requestOptions);
const taskList: { id: string } | undefined = response.value[0];

if (!taskList) {
return Promise.reject(`The specified task list does not exist`);
}
if (!taskList) {
throw `The specified task list does not exist`;
}

return Promise.resolve(taskList.id);
});
return taskList.id;
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
Expand Down
76 changes: 38 additions & 38 deletions src/m365/todo/commands/task/task-remove.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe(commands.TASK_REMOVE, () => {

before(() => {
cli = Cli.getInstance();
sinon.stub(auth, 'restoreAuth').callsFake(() => Promise.resolve());
sinon.stub(telemetry, 'trackEvent').callsFake(() => { });
sinon.stub(pid, 'getProcessName').callsFake(() => '');
sinon.stub(session, 'getId').callsFake(() => '');
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.service.connected = true;
sinon.stub(Cli, 'prompt').callsFake(async (options) => {
promptOptions = options;
Expand Down Expand Up @@ -64,17 +64,17 @@ describe(commands.TASK_REMOVE, () => {
});

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

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

it('removes a To Do task by task id and task list name', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists?$filter=displayName eq 'Tasks'`) {
return Promise.resolve({
return {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('eded3a2a-8f01-40aa-998a-e4f02ec693ba')/todo/lists",
"value": [
{
Expand All @@ -86,18 +86,18 @@ describe(commands.TASK_REMOVE, () => {
"id": "BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB="
}
]
});
};
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});

sinon.stub(request, 'delete').callsFake((opts) => {
sinon.stub(request, 'delete').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists/BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB=/tasks/AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhAAA=`) {
return Promise.resolve();
return;
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});

await command.action(logger, {
Expand All @@ -110,9 +110,9 @@ describe(commands.TASK_REMOVE, () => {
});

it('removes a To Do task by task id and task list name when confirm option is passed', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists?$filter=displayName eq 'Tasks'`) {
return Promise.resolve({
return {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('eded3a2a-8f01-40aa-998a-e4f02ec693ba')/todo/lists",
"value": [
{
Expand All @@ -124,17 +124,17 @@ describe(commands.TASK_REMOVE, () => {
"id": "BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB="
}
]
});
};
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});
sinon.stub(request, 'delete').callsFake((opts) => {
sinon.stub(request, 'delete').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists/BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB=/tasks/AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhAAA=`) {
return Promise.resolve();
return;
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});

await command.action(logger, {
Expand All @@ -148,27 +148,27 @@ describe(commands.TASK_REMOVE, () => {
});

it('removes a To Do task by task id and task list id', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists/BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB=`) {
return Promise.resolve({
return {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('eded3a2a-8f01-40aa-998a-e4f02ec693ba')/todo/lists/$entity",
"@odata.etag": "W/\"tPAryi+qT0uvQKa/pHXU5AAAQchLxw==\"",
"displayName": "Tasks",
"isOwner": true,
"isShared": false,
"wellknownListName": "defaultList",
"id": "BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB="
});
};
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});
sinon.stub(request, 'delete').callsFake((opts) => {
sinon.stub(request, 'delete').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists/BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB=/tasks/AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhAAA=`) {
return Promise.resolve();
return;
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});

await command.action(logger, {
Expand All @@ -181,9 +181,9 @@ describe(commands.TASK_REMOVE, () => {
});

it('handles error correctly', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists?$filter=displayName eq 'FooList'`) {
return Promise.resolve({
return {
"error": {
"code": "invalidRequest",
"message": "The list FooList cannot be found",
Expand All @@ -195,13 +195,13 @@ describe(commands.TASK_REMOVE, () => {
"client-request-id": "085a2508-e115-63b6-fcc9-05acc2133231"
}
}
});
};
}

return Promise.reject('The list FooList cannot be found');
throw 'The list FooList cannot be found';
});
sinon.stub(request, 'delete').callsFake(() => {
return Promise.reject('Invalid request');
throw 'Invalid request';
});

await assert.rejects(command.action(logger, {
Expand All @@ -214,9 +214,9 @@ describe(commands.TASK_REMOVE, () => {
});

it('prompts before removing the To Do task when confirm option not passed', async () => {
sinon.stub(request, 'get').callsFake((opts) => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists?$filter=displayName eq 'Tasks'`) {
return Promise.resolve({
return {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('eded3a2a-8f01-40aa-998a-e4f02ec693ba')/todo/lists",
"value": [
{
Expand All @@ -228,17 +228,17 @@ describe(commands.TASK_REMOVE, () => {
"id": "BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB="
}
]
});
};
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});
sinon.stub(request, 'delete').callsFake((opts) => {
sinon.stub(request, 'delete').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/me/todo/lists/BBMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhBBB=/tasks/AAMkAGI3NDhlZmQzLWQxYjAtNGJjNy04NmYwLWQ0M2IzZTNlMDUwNAAuAAAAAACQ1l2jfH6VSZraktP8Z7auAQCbV93BagWITZhL3J6BMqhjAAD9pHIhAAA=`) {
return Promise.resolve();
return;
}

return Promise.reject('Invalid request');
throw 'Invalid request';
});

sinonUtil.restore(Cli.prompt);
Expand Down
Loading