diff --git a/docs/graph/planner.md b/docs/graph/planner.md index dd24ee8e3..374eeb122 100644 --- a/docs/graph/planner.md +++ b/docs/graph/planner.md @@ -5,7 +5,7 @@ you can add, update and delete items in Planner. More information can be found in the official Graph documentation: -- [Planner Resource Type](https://docs.microsoft.com/en-us/graph/api/resources/plannertask?view=graph-rest-1.0) +- [Tasks and plans](https://learn.microsoft.com/en-us/graph/api/resources/planner-overview?view=graph-rest-1.0) ## IInvitations @@ -22,7 +22,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const plan = await graph.planner.plans.getById('planId')(); +const plan = await graph.planner.plans.getById({planId})(); ``` @@ -36,7 +36,14 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const newPlan = await graph.planner.plans.add('groupObjectId', 'title'); +const planTemplate: IPlanAdd = { + container: { + url: "", + }, + title: "", +}; + +const plan = await graph.planner.plans.add(planTemplate); ``` @@ -50,7 +57,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const planTasks = await graph.planner.plans.getById('planId').tasks(); +const planTasks = await graph.planner.plans.getById({planId}).tasks(); ``` @@ -64,7 +71,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const planBuckets = await graph.planner.plans.getById('planId').buckets(); +const planBuckets = await graph.planner.plans.getById({planId}).buckets(); ``` @@ -78,7 +85,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const planDetails = await graph.planner.plans.getById('planId').details(); +const planDetails = await graph.planner.plans.getById({planId}).details(); ``` @@ -92,7 +99,8 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const delPlan = await graph.planner.plans.getById('planId').delete('planEtag'); +// Note the planETag cannot be "*" and is required. +const delPlan = await graph.planner.plans.getById({planId}).delete({planEtag}); ``` @@ -106,7 +114,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const updPlan = await graph.planner.plans.getById('planId').update({title: 'New Title', eTag: 'planEtag'}); +const updPlan = await graph.planner.plans.getById({planId}).update({title: 'New Title', eTag: {planEtag}}); ``` @@ -116,11 +124,13 @@ Using the tasks() you can get the Tasks across all plans ```TypeScript import { graphfi } from "@pnp/graph"; +import "@pnp/graph/users"; import "@pnp/graph/planner"; const graph = graphfi(...); -const planTasks = await graph.me.tasks() +const planTasks = await graph.me.tasks(); +const planTasks = await graph.users.getById({userId}).tasks(); ``` @@ -135,7 +145,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const task = await graph.planner.tasks.getById('taskId')(); +const task = await graph.planner.tasks.getById({taskId})(); ``` @@ -149,7 +159,17 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const newTask = await graph.planner.tasks.add('planId', 'title'); +const taskTemplate = { + planId: {planId}, + title: "My New Task", + assignments: { + {userId}: { + "@odata.type": "#microsoft.graph.plannerAssignment", + orderHint: " !", + } + }, +}; +const newTask = await graph.planner.tasks.add({taskTemplate}); ``` @@ -163,7 +183,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const taskDetails = await graph.planner.tasks.getById('taskId').details(); +const taskDetails = await graph.planner.tasks.getById({taskId}).details(); ``` @@ -177,7 +197,8 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const delTask = await graph.planner.tasks.getById('taskId').delete('taskEtag'); +// Note the taskEtag cannot be "*" and is required. +const delTask = await graph.planner.tasks.getById({taskId}).delete({taskEtag}); ``` @@ -191,7 +212,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const updTask = await graph.planner.tasks.getById('taskId').update({properties, eTag:'taskEtag'}); +const updTask = await graph.planner.tasks.getById({taskId}).update({properties, eTag: {taskEtag}}); ``` @@ -206,7 +227,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const bucket = await graph.planner.buckets.getById('bucketId')(); +const bucket = await graph.planner.buckets.getById({bucketId})(); ``` @@ -220,7 +241,11 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const newBucket = await graph.planner.buckets.add('name', 'planId'); +const bucketTemplate = { + planId: {planId}, + name: "My Task Bucket", +}; +const newBucket = await graph.planner.buckets.add(bucketTemplate); ``` @@ -234,7 +259,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const updBucket = await graph.planner.buckets.getById('bucketId').update({name: "Name", eTag:'bucketEtag'}); +const updBucket = await graph.planner.buckets.getById({bucketId}).update({name: "New Name", eTag: {bucketEtag}}); ``` @@ -248,7 +273,8 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const delBucket = await graph.planner.buckets.getById('bucketId').delete(eTag:'bucketEtag'); +// Note the bucketEtag cannot be "*" and is required. +const delBucket = await graph.planner.buckets.getById({bucketId}).delete(eTag: {bucketEtag}); ``` @@ -262,7 +288,7 @@ import "@pnp/graph/planner"; const graph = graphfi(...); -const bucketTasks = await graph.planner.buckets.getById('bucketId').tasks(); +const bucketTasks = await graph.planner.buckets.getById({bucketId}).tasks(); ``` @@ -280,3 +306,29 @@ const graph = graphfi(...); const plans = await graph.groups.getById("b179a282-9f94-4bb5-a395-2a80de5a5a78").plans(); ``` + +## Get AssignedToTaskBoardFormat, BucketTaskBoardFormat, ProgressTaskBoardTaskFormat + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/planner"; + +const graph = graphfi(...); + +const assignedToTaskBoardFormat = await this.pnp.graph.planner.tasks.getById({taskId}).assignedToTaskBoardFormat(); +const bucketTaskBoardFormat = await this.pnp.graph.planner.tasks.getById({taskId}).assignedToTaskBoardFormat(); +const progressTaskBoardTaskFormat = await this.pnp.graph.planner.tasks.getById({taskId}).progressTaskBoardTaskFormat(); +``` + +## Update AssignedToTaskBoardFormat, BucketTaskBoardFormat, ProgressTaskBoardTaskFormat + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/planner"; + +const graph = graphfi(...); + +await this.pnp.graph.planner.tasks.getById({taskId}).assignedToTaskBoardFormat.update({ unassignedOrderHint: " abc!" }, {taskETag}); +await this.pnp.graph.planner.tasks.getById({taskId}).assignedToTaskBoardFormat.update({orderHint: " abc!" }, {taskETag}); +await this.pnp.graph.planner.tasks.getById({taskId}).progressTaskBoardTaskFormat.update({orderHint: " abc!" }, {taskETag}); +``` diff --git a/package.json b/package.json index 0ee4b834e..a82a53b6a 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "scripts": { "build": "npm run pnp-buildsystem-init && pnpbuild -n build", "build-localresolver": "npx tsc -p tsconfig.localresolver.json", - "buildDebug": "npm run pnp-buildsystem-init && pnpbuild -n build-debug", + "buildDebug": "npm run clean && npm run pnp-buildsystem-init && pnpbuild -n build-debug", "clean": "del-cli \"./?(dist|site|build|buildsystem-config.js)\"", "lint": "eslint ./packages ./test --ext .ts", "package": "npm run pnp-buildsystem-init && pnpbuild -n package", diff --git a/packages/graph/planner/index.ts b/packages/graph/planner/index.ts index 3a648e7f1..0506ec5b3 100644 --- a/packages/graph/planner/index.ts +++ b/packages/graph/planner/index.ts @@ -8,14 +8,12 @@ export { Bucket, Buckets, IBucket, - IBucketAddResult, IBuckets, IPlan, - IPlanAddResult, + IPlanAdd, IPlanner, IPlans, ITask, - ITaskAddResult, ITasks, ITaskDetails, Plan, diff --git a/packages/graph/planner/types.ts b/packages/graph/planner/types.ts index daf3f34c1..5a17d8052 100644 --- a/packages/graph/planner/types.ts +++ b/packages/graph/planner/types.ts @@ -5,10 +5,13 @@ import { PlannerTaskDetails as IPlannerTaskDetailsType, PlannerBucket as IPlannerBucketType, Planner as IPlannerType, + PlannerPlanContainer as IPlannerPlanContainerType, + PlannerAssignedToTaskBoardTaskFormat as IPlannerAssignedToTaskBoardTaskFormatType, + PlannerBucketTaskBoardTaskFormat as IPlannerBucketTaskBoardTaskFormatType, + PlannerProgressTaskBoardTaskFormat as IPlannerProgressTaskBoardTaskFormatType, } from "@microsoft/microsoft-graph-types"; -import { body } from "@pnp/queryable"; -import { _GraphInstance, _GraphCollection, graphInvokableFactory, graphPost } from "../graphqueryable.js"; -import { getById, IGetById, deleteableWithETag, IDeleteableWithETag, updateableWithETag, IUpdateableWithETag } from "../decorators.js"; +import { _GraphInstance, _GraphCollection, graphInvokableFactory } from "../graphqueryable.js"; +import { getById, IGetById, deleteableWithETag, IDeleteableWithETag, updateableWithETag, IUpdateableWithETag, addable, IAddable } from "../decorators.js"; import { defaultPath } from "../decorators.js"; /** @@ -42,7 +45,7 @@ export const Planner = graphInvokableFactory(_Planner); @updateableWithETag() export class _PlanDetails extends _GraphInstance { } export interface IPlanDetails extends _PlanDetails, IUpdateableWithETag { } -export const PlanDetails = graphInvokableFactory(_PlanDetails); +export const PlanDetails = graphInvokableFactory(_PlanDetails); /** * Plan @@ -68,24 +71,9 @@ export const Plan = graphInvokableFactory(_Plan); @defaultPath("plans") @getById(Plan) -export class _Plans extends _GraphCollection { - /** - * Create a new Planner Plan. - * - * @param owner Id of Group object. - * @param title The Title of the Plan. - */ - public async add(owner: string, title: string): Promise { - - const data = await graphPost(this, body({ owner, title })); - - return { - data, - plan: (this).getById(data.id), - }; - } -} -export interface IPlans extends _Plans, IGetById { } +@addable() +export class _Plans extends _GraphCollection {} +export interface IPlans extends _Plans, IGetById, IAddable { } export const Plans = graphInvokableFactory(_Plans); /** @@ -97,6 +85,33 @@ export class _TaskDetails extends _GraphInstance { } export interface ITaskDetails extends _TaskDetails, IUpdateableWithETag { } export const TaskDetails = graphInvokableFactory(_TaskDetails); +/** + * AssignedToTaskBoardFormat + */ +@defaultPath("assignedToTaskBoardFormat") +@updateableWithETag() +export class _AssignedToTaskBoardFormat extends _GraphInstance { } +export interface IAssignedToTaskBoardFormat extends _AssignedToTaskBoardFormat, IUpdateableWithETag { } +export const AssignedToTaskBoardFormat = graphInvokableFactory(_AssignedToTaskBoardFormat); + +/** + * BucketTaskBoardFormat + */ +@defaultPath("bucketTaskBoardFormat") +@updateableWithETag() +export class _BucketTaskBoardFormat extends _GraphInstance { } +export interface IBucketTaskBoardFormat extends _BucketTaskBoardFormat, IUpdateableWithETag { } +export const BucketTaskBoardFormat = graphInvokableFactory(_BucketTaskBoardFormat); + +/** + * ProgressTaskBoardFormat + */ +@defaultPath("progressTaskBoardFormat") +@updateableWithETag() +export class _ProgressTaskBoardFormat extends _GraphInstance { } +export interface IProgressTaskBoardFormat extends _ProgressTaskBoardFormat, IUpdateableWithETag { } +export const ProgressTaskBoardFormat = graphInvokableFactory(_ProgressTaskBoardFormat); + /** * Task */ @@ -106,6 +121,18 @@ export class _Task extends _GraphInstance { public get details(): ITaskDetails { return TaskDetails(this); } + + public get assignedToTaskBoardFormat(): IAssignedToTaskBoardFormat { + return AssignedToTaskBoardFormat(this); + } + + public get bucketTaskBoardFormat(): IBucketTaskBoardFormat { + return BucketTaskBoardFormat(this); + } + + public get progressTaskBoardFormat(): IProgressTaskBoardFormat { + return ProgressTaskBoardFormat(this); + } } export interface ITask extends _Task, IUpdateableWithETag, IDeleteableWithETag { } export const Task = graphInvokableFactory(_Task); @@ -115,39 +142,9 @@ export const Task = graphInvokableFactory(_Task); */ @defaultPath("tasks") @getById(Task) -export class _Tasks extends _GraphCollection { - /** - * Create a new Planner Task. - * - * @param planId Id of Plan. - * @param title The Title of the Task. - * @param assignments Assign the task - * @param bucketId Id of Bucket - */ - public async add(planId: string, title: string, assignments?: Record, bucketId?: string): Promise { - - let postBody = { - planId, - title, - ...assignments, - }; - - if (bucketId) { - postBody = { - ...postBody, - bucketId, - }; - } - - const data = await graphPost(this, body(postBody)); - - return { - data, - task: (this).getById(data.id), - }; - } -} -export interface ITasks extends _Tasks, IGetById { } +@addable() +export class _Tasks extends _GraphCollection {} +export interface ITasks extends _Tasks, IGetById, IAddable { } export const Tasks = graphInvokableFactory(_Tasks); /** @@ -169,44 +166,13 @@ export const Bucket = graphInvokableFactory(_Bucket); */ @defaultPath("buckets") @getById(Bucket) -export class _Buckets extends _GraphCollection { - /** - * Create a new Bucket. - * - * @param name Name of Bucket object. - * @param planId The Id of the Plan. - * @param oderHint Hint used to order items of this type in a list view. - */ - public async add(name: string, planId: string, orderHint?: string): Promise { - - const postBody = { - name: name, - orderHint: orderHint ? orderHint : "", - planId: planId, - }; - - const data = await graphPost(this, body(postBody)); - - return { - bucket: (this).getById(data.id), - data, - }; - } -} -export interface IBuckets extends _Buckets, IGetById { } +@addable() +export class _Buckets extends _GraphCollection {} +export interface IBuckets extends _Buckets, IGetById, IAddable { } export const Buckets = graphInvokableFactory(_Buckets); -export interface IBucketAddResult { - data: IPlannerBucketType; - bucket: IBucket; +export interface IPlanAdd { + container: IPlannerPlanContainerType; + title: string; } -export interface IPlanAddResult { - data: IPlannerPlanType; - plan: IPlan; -} - -export interface ITaskAddResult { - data: IPlannerTaskType; - task: ITask; -} diff --git a/test/graph/planner.ts b/test/graph/planner.ts index 0ab7fb016..c535e4943 100644 --- a/test/graph/planner.ts +++ b/test/graph/planner.ts @@ -1,160 +1,451 @@ -import { getRandomString } from "@pnp/core"; +import { getRandomString, stringIsNullOrEmpty } from "@pnp/core"; import { expect } from "chai"; -import { GroupType } from "@pnp/graph/groups"; import "@pnp/graph/planner"; +import { IPlanAdd } from "@pnp/graph/planner"; +import getValidUser from "./utilities/getValidUser.js"; // Tests can't be run until planner support application permissions, incomplete -describe.skip("Planner", function () { +describe.only("Planner", function () { + const planTemplate: IPlanAdd = { + container: { + url: "", + }, + title: "", + }; - let groupID = ""; - let planID = ""; - let taskID = ""; + const PlanIds = []; - before(function () { + before(async function () { - if (!this.pnp.settings.enableWebTests) { + if ((!this.pnp.settings.enableWebTests) || (!this.pnp.settings.testGroupId)) { this.skip(); } + planTemplate.container.url = `https://graph.microsoft.com/v1.0/groups/${this.pnp.settings.testGroupId}`; }); - beforeEach(async function () { - // Clear out variables - groupID = ""; - planID = ""; - taskID = ""; - }); + describe("Plans", function () { - it("addPlan", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const plan = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = plan.data.id; - return expect(plan.data.title).is.equal(planName); - }); + it("List", async function () { + const planName = `TestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + const plans = await this.pnp.graph.groups.getById(this.pnp.settings.testGroupId).plans(); + let planExists = false; + plans.forEach(element => { + if (element.id === planAdd.id) { + planExists = true; + return planExists === true; + } + }); + return expect(planExists).is.true; + }); - it("getPlan", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - const plan = await this.pnp.graph.planner.plans.getById(planID)(); - return expect(plan.title).is.equal(planName); - }); + it("Add", async function () { + const planName = `TestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + return expect(planAdd.title).is.equal(planName); + }); - it("updatePlan", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - const newPlanName = `TestPlan_${getRandomString(4)}`; - await this.pnp.graph.planner.plans.getById(planID).update({ title: newPlanName }, planAddResult.data["@odata.etag"]); - const planUpdate = await this.pnp.graph.planner.plans.getById(planID)(); - return expect(planUpdate.title).is.equal(newPlanName); - }); + it("GetById", async function () { + const planName = `TestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + const plan = await this.pnp.graph.planner.plans.getById(planAdd.id)(); + return expect(plan.title).is.equal(planName); + }); - it("deletePlan", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - await this.pnp.graph.planner.plans.getById(planID).delete(); - const plan = await this.pnp.graph.planner.plans.getById(planID)(); - planID = ""; - return expect(plan).is.undefined; - }); + it("Update", async function () { + const planName = `TestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + const newPlanName = `TestPlan_${getRandomString(4)}`; + await this.pnp.graph.planner.plans.getById(planAdd.id).update({ title: newPlanName }, planAdd["@odata.etag"]); + const planUpdate = await this.pnp.graph.planner.plans.getById(planAdd.id)(); + return expect(planUpdate.title).is.equal(newPlanName); + }); - it("getPlanDetails", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - const planDetails = await this.pnp.graph.planner.plans.getById(planID).details(); - return expect(planDetails.id).is.equal(planID); - }); + it("Delete", async function () { + const planName = `TestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + await this.pnp.graph.planner.plans.getById(planAdd.id).delete(planAdd["@odata.etag"]); + let plan = "FAILED"; + try { + await this.pnp.graph.planner.plans.getById(planAdd.id)(); + } catch (e) { + plan = null; + } + return expect(plan).is.null; + }); + + it("GetDetails", async function () { + const planName = `TestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + const planDetails = await this.pnp.graph.planner.plans.getById(planAdd.id).details(); + return expect(planDetails.id).length.greaterThan(0); + }); - it("addPlanTasks", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - const taskName = `TestTask_${getRandomString(4)}`; - const planTaskResult = await this.pnp.graph.planner.plans.getById(planID).tasks.add(planID, taskName); - taskID = planTaskResult.data.id; - return expect(planTaskResult.data.id).is.not.undefined; + it("UpdateDetails", async function () { + const planName = `TestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + const category = `TestCategory_${getRandomString(4)}`; + const planDetails = await this.pnp.graph.planner.plans.getById(planAdd.id).details(); + await this.pnp.graph.planner.plans.getById(planAdd.id).details.update({ categoryDescriptions: { category1: category } }, planDetails["@odata.etag"]); + const planDetailsCheck = await this.pnp.graph.planner.plans.getById(planAdd.id).details(); + return expect(planDetailsCheck.categoryDescriptions.category1).is.equal(category); + }); }); - it("getPlanTasks", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - const taskName = `TestTask_${getRandomString(4)}`; - const planTaskResult = await this.pnp.graph.planner.plans.getById(planID).tasks.add(planID, taskName); - taskID = planTaskResult.data.id; - const tasks = await this.pnp.graph.planner.plans.getById(planID).tasks(); - let taskExists = false; - tasks.forEach(element => { - if (element.id === taskID) { - taskExists = true; - return taskExists === true; + describe("Buckets", function () { + let PlanID = null; + const bucketTemplate = { + planId: "", + name: "", + }; + + before(async function () { + const planName = `BucketTestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + PlanID = planAdd.id; + bucketTemplate.planId = PlanID; + }); + + it("List", async function () { + const bucketName = `TestBucket_${getRandomString(4)}`; + const newBucket = JSON.parse(JSON.stringify(bucketTemplate)); + newBucket.name = bucketName; + const planTaskResult = await this.pnp.graph.planner.buckets.add(newBucket); + const buckets = await this.pnp.graph.groups.getById(this.pnp.settings.testGroupId).plans.getById(PlanID).buckets(); + let bucketExists = false; + buckets.forEach(element => { + if (element.id === planTaskResult.id) { + bucketExists = true; + return bucketExists === true; + } + }); + return expect(bucketExists).is.true; + }); + + it("Add", async function () { + const bucketName = `TestBucket_${getRandomString(4)}`; + const newBucket = JSON.parse(JSON.stringify(bucketTemplate)); + newBucket.name = bucketName; + const planBucketResult = await this.pnp.graph.planner.buckets.add(newBucket); + return expect(planBucketResult.id).is.not.undefined; + }); + + it("GetById", async function () { + const bucketName = `TestBucket_${getRandomString(4)}`; + const newBucket = JSON.parse(JSON.stringify(bucketTemplate)); + newBucket.name = bucketName; + const planBucketResult = await this.pnp.graph.planner.buckets.add(newBucket); + const bucket = await this.pnp.graph.planner.buckets.getById(planBucketResult.id)(); + return expect(bucket.name).is.equal(bucketName); + }); + + it("Update", async function () { + const bucketName = `TestBucket_${getRandomString(4)}`; + const newBucket = JSON.parse(JSON.stringify(bucketTemplate)); + newBucket.name = bucketName; + const planBucketAdd = await this.pnp.graph.planner.buckets.add(newBucket); + const newBucketName = `TestBucket_${getRandomString(4)}`; + await this.pnp.graph.planner.buckets.getById(planBucketAdd.id).update({ name: newBucketName }, planBucketAdd["@odata.etag"]); + const bucket = await this.pnp.graph.planner.buckets.getById(planBucketAdd.id)(); + return expect(bucket.name).is.equal(newBucketName); + }); + + it("Delete", async function () { + const bucketName = `TestBucket_${getRandomString(4)}`; + const newBucket = JSON.parse(JSON.stringify(bucketTemplate)); + newBucket.name = bucketName; + const planBucketAdd = await this.pnp.graph.planner.buckets.add(newBucket); + await this.pnp.graph.planner.buckets.getById(planBucketAdd.id).delete(planBucketAdd["@odata.etag"]); + let bucket = "FAILED"; + try { + bucket = await this.pnp.graph.planner.plans.getById(PlanID).buckets.getById(planBucketAdd.id)(); + } catch (e) { + bucket = null; } + return expect(bucket).is.null; }); - return expect(taskExists).is.not.true; }); - it("getTasksById", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - const taskName = `TestTask_${getRandomString(4)}`; - const planTaskResult = await this.pnp.graph.planner.plans.getById(planID).tasks.add(planID, taskName); - taskID = planTaskResult.data.id; - const task = await this.pnp.graph.planner.tasks.getById(taskID)(); - return expect(task.id).is.equal(taskID); + + describe("Tasks", function () { + + let PlanID = null; + let BucketID = null; + + const taskTemplate = { + planId: "", + bucketId: "", + title: "", + }; + + before(async function () { + const planName = `TaskTestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + PlanID = planAdd.id; + taskTemplate.planId = PlanID; + const newBucket = { planId: PlanID, name: `TaskTestBucket_${getRandomString(4)}` }; + const planBucketResult = await this.pnp.graph.planner.buckets.add(newBucket); + BucketID = planBucketResult.id; + taskTemplate.bucketId = BucketID; + }); + + it("List", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskResult = await this.pnp.graph.planner.tasks.add(newTask); + const tasks = await this.pnp.graph.planner.plans.getById(PlanID).tasks(); + let taskExists = false; + tasks.forEach(element => { + if (element.id === planTaskResult.id) { + taskExists = true; + return taskExists === true; + } + }); + return expect(taskExists).is.true; + }); + + it("Add", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskResult = await this.pnp.graph.planner.tasks.add(newTask); + return expect(planTaskResult.id).is.not.undefined; + }); + + it("GetById", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskResult = await this.pnp.graph.planner.tasks.add(newTask); + const task = await this.pnp.graph.planner.tasks.getById(planTaskResult.id)(); + return expect(task.title).is.equal(taskName); + }); + + it("Update", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const newTaskName = `TestTask_${getRandomString(4)}`; + await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).update({ title: newTaskName }, planTaskAdd["@odata.etag"]); + const task = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id)(); + return expect(task.title).is.equal(newTaskName); + }); + + it("Delete", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).delete(planTaskAdd["@odata.etag"]); + let task = "FAILED"; + try { + task = await this.pnp.graph.planner.plans.getById(PlanID).tasks.getById(planTaskAdd.id)(); + } catch (e) { + task = null; + } + return expect(task).is.null; + }); + + it("GetDetails", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const planTaskDetails = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).details(); + return expect(planTaskDetails.id).length.greaterThan(0); + }); + + it("UpdateDetails", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const planTaskDetails = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).details(); + const description = `TestDescription_${getRandomString(4)}`; + await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).details.update({ description: description }, planTaskDetails["@odata.etag"]); + const planTaskDetailsCheck = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).details(); + return expect(planTaskDetailsCheck.description).is.equal(description); + }); + + it("Plan: ListTasks", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskResult = await this.pnp.graph.planner.tasks.add(newTask); + const planTasks = await this.pnp.graph.planner.plans.getById(PlanID).tasks(); + let planExists = false; + planTasks.forEach(element => { + if (element.id === planTaskResult.id) { + planExists = true; + return planExists === true; + } + }); + return expect(planExists).is.true; + }); + + it("Bucket: ListTasks", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskResult = await this.pnp.graph.planner.tasks.add(newTask); + const bucketTasks = await this.pnp.graph.planner.buckets.getById(BucketID).tasks(); + let bucketExists = false; + bucketTasks.forEach(element => { + if (element.id === planTaskResult.id) { + bucketExists = true; + return bucketExists === true; + } + }); + return expect(bucketExists).is.true; + }); + + it("AssignedTaskBoardFormat: Get", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const atbf = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).assignedToTaskBoardFormat(); + return expect(atbf.id).length.greaterThan(0); + }); + + it("AssignedTaskBoardFormat: Update", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const atbf = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).assignedToTaskBoardFormat(); + const newValue = " 123!"; + await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).assignedToTaskBoardFormat.update({ unassignedOrderHint: newValue }, atbf["@odata.etag"]); + const atbfUpdate = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).assignedToTaskBoardFormat(); + return expect(atbfUpdate.unassignedOrderHint).is.not.empty; + }); + + it("BucketTaskBoardFormat: Get", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const btbf = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).bucketTaskBoardFormat(); + return expect(btbf.id).length.greaterThan(0); + }); + + it("BucketTaskBoardFormat: Update", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const btbf = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).bucketTaskBoardFormat(); + const newValue = " 123!"; + await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).bucketTaskBoardFormat.update({ orderHint: newValue }, btbf["@odata.etag"]); + const btbfUpdate = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).bucketTaskBoardFormat(); + return expect(btbfUpdate.orderHint).is.not.empty; + }); + + it("ProgressTaskBoardTaskFormat: Get", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const ptbf = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).progressTaskBoardFormat(); + return expect(ptbf.id).length.greaterThan(0); + }); + + it("ProgressTaskBoardTaskFormat: Update", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskAdd = await this.pnp.graph.planner.tasks.add(newTask); + const ptbf = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).progressTaskBoardFormat(); + const newValue = " 123!"; + await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).progressTaskBoardFormat.update({ orderHint: newValue }, ptbf["@odata.etag"]); + const ptbfUpdate = await this.pnp.graph.planner.tasks.getById(planTaskAdd.id).progressTaskBoardFormat(); + return expect(ptbfUpdate.orderHint).is.not.empty; + }); + + }); - it("updateTask", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); - groupID = groupAddResult.data.id; - const planName = `TestPlan_${getRandomString(4)}`; - const planAddResult = await this.pnp.graph.planner.plans.add(groupID, planName); - planID = planAddResult.data.id; - const taskName = `TestTask_${getRandomString(4)}`; - const planTaskResult = await this.pnp.graph.planner.plans.getById(planID).tasks.add(planID, taskName); - taskID = planTaskResult.data.id; - const task = await this.pnp.graph.planner.tasks.getById(taskID)(); - return expect(task.id).is.equal(taskID); + describe("User Tasks", function () { + let PlanID = null; + let testUserName = null; + const taskTemplate = { + planId: "", + title: "", + assignments: {}, + }; + + before(async function () { + if (!this.pnp.settings.enableWebTests || stringIsNullOrEmpty(this.pnp.settings.testUser)) { + this.skip(); + } + + const planName = `TaskTestPlan_${getRandomString(4)}`; + const newPlan = JSON.parse(JSON.stringify(planTemplate)); + newPlan.title = planName; + const planAdd = await this.pnp.graph.planner.plans.add(newPlan); + PlanIds.push(planAdd.id); + PlanID = planAdd.id; + const userInfo = await getValidUser.call(this); + testUserName = userInfo.userPrincipalName; + const user = await this.pnp.graph.users.getById(testUserName)(); + taskTemplate.planId = PlanID; + taskTemplate.assignments[user.id] = { + "@odata.type": "#microsoft.graph.plannerAssignment", + orderHint: " !", + }; + }); + + it("List", async function () { + const taskName = `TestTask_${getRandomString(4)}`; + const newTask = JSON.parse(JSON.stringify(taskTemplate)); + newTask.title = taskName; + const planTaskResult = await this.pnp.graph.planner.tasks.add(newTask); + const userTasks = await this.pnp.graph.users.getById(testUserName).tasks(); + let taskExists = false; + userTasks.forEach(element => { + if (element.id === planTaskResult.id) { + taskExists = true; + return taskExists === true; + } + }); + return expect(taskExists).is.true; + }); }); - afterEach(async function () { - const promises = [Promise.resolve()]; - if (taskID !== "") { - promises.push(this.pnp.graph.planner.plans.getById(planID).tasks.getById(taskID).delete()); - } - if (planID !== "") { - promises.push(this.pnp.graph.planner.plans.getById(planID).delete()); - } - if (groupID !== "") { - promises.push(this.pnp.graph.groups.getById(groupID).delete()); + after(async function () { + if (PlanIds.length > 0) { + PlanIds.forEach(async (id) => { + await this.pnp.graph.planner.plans.getById(id).delete(); + }); } - return Promise.all(promises); }); });