From f33d47ca5a00efb98886c460e234fd1efc9f0b28 Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Wed, 26 Jul 2023 13:42:01 -0400 Subject: [PATCH] adding pnpTest WIP --- test/core/assumptions.ts | 9 ++- test/core/storage.ts | 29 +++---- test/core/timeline.ts | 25 +++--- test/core/util.ts | 138 +++++++++++++++++++-------------- test/graph/batch.ts | 26 ++++--- test/graph/calendars.ts | 2 + test/graph/columns.ts | 138 ++++++++++++++++++++++----------- test/graph/contacts.ts | 2 + test/graph/content-types.ts | 135 ++++++++++++++++++++++---------- test/graph/directoryobjects.ts | 87 ++++++++++++--------- test/graph/groups.ts | 84 +++++++++----------- test/graph/lists.ts | 42 ++++++---- test/pnp-test.ts | 10 +++ test/test-recording.ts | 3 + 14 files changed, 447 insertions(+), 283 deletions(-) diff --git a/test/core/assumptions.ts b/test/core/assumptions.ts index 780047807..38e17eafe 100644 --- a/test/core/assumptions.ts +++ b/test/core/assumptions.ts @@ -3,10 +3,11 @@ // our assumptions remain correct import { expect } from "chai"; +import { pnpTest } from "../pnp-test.js"; describe("Assumptions", function () { - it("JS should merge objects how we expect", function () { + it("JS should merge objects how we expect", pnpTest("3576d9bf-aa31-4b3f-8400-104513956328", function () { const o = {}; @@ -58,9 +59,9 @@ describe("Assumptions", function () { expect(test5, "test 5").to.eql({}); - }); + })); - it("should destructure how we assume", function () { + it("should destructure how we assume", pnpTest("67a889c9-a45a-4978-a181-91d5d096edeb", function () { const props = { yes: false, @@ -95,5 +96,5 @@ describe("Assumptions", function () { expect(title).to.eq("hello"); expect(another).to.eq("something"); - }); + })); }); diff --git a/test/core/storage.ts b/test/core/storage.ts index 81953379e..e0017430f 100644 --- a/test/core/storage.ts +++ b/test/core/storage.ts @@ -1,5 +1,6 @@ import { expect } from "chai"; import { PnPClientStorage } from "@pnp/core"; +import { pnpTest } from "../pnp-test.js"; describe("Storage", function () { @@ -7,54 +8,54 @@ describe("Storage", function () { let storage: PnPClientStorage; - beforeEach(function () { + beforeEach(pnpTest("71bacb4d-2a28-4da3-a09b-7b8625345586", function () { storage = new PnPClientStorage(); - }); + })); - it("Add and Get a value (local)", function () { + it("Add and Get a value (local)", pnpTest("4986f3f6-3b31-4ac5-9746-62384a108ae1", function () { storage.local.put("test", "value"); const ret = storage.local.get("test"); expect(ret).to.eq("value"); - }); + })); - it("Add two values, remove one and still return the other (local)", function () { + it("Add two values, remove one and still return the other (local)", pnpTest("b370742a-0eb9-40f5-bb75-43b667f51181", function () { storage.local.put("test1", "value1"); storage.local.put("test2", "value2"); storage.local.delete("test1"); const ret = storage.local.get("test2"); expect(ret).to.eq("value2"); - }); + })); - it("Use getOrPut to add a value using a getter function and return it (local)", function () { + it("Use getOrPut to add a value using a getter function and return it (local)", pnpTest("6f8a3a57-6e1e-4e26-9c86-2bfb05085c5e", function () { storage.local.getOrPut("test", function () { return new Promise(() => "value"); }).then(function () { const ret = storage.local.get("test"); expect(ret).to.eq("value"); }); - }); + })); - it("Add and Get a value (session)", function () { + it("Add and Get a value (session)", pnpTest("71cc7886-18d7-4362-b232-07afd7d6b750", function () { storage.session.put("test", "value"); const ret = storage.session.get("test"); expect(ret).to.eq("value"); - }); + })); - it("Add two values, remove one and still return the other (session)", function () { + it("Add two values, remove one and still return the other (session)", pnpTest("8c570f93-d6aa-49f3-a740-d884f1832b59", function () { storage.session.put("test1", "value1"); storage.session.put("test2", "value2"); storage.session.delete("test1"); const ret = storage.session.get("test2"); expect(ret).to.eq("value2"); - }); + })); - it("Use getOrPut to add a value using a getter function and return it (session)", function () { + it("Use getOrPut to add a value using a getter function and return it (session)", pnpTest("0c25edf5-120e-48d3-b6cd-e2da49391d21", function () { storage.session.getOrPut("test", function () { return new Promise(() => "value"); }).then(function () { const ret = storage.session.get("test"); expect(ret).to.eq("value"); }); - }); + })); }); }); diff --git a/test/core/timeline.ts b/test/core/timeline.ts index a3ab8543e..3d509f362 100644 --- a/test/core/timeline.ts +++ b/test/core/timeline.ts @@ -1,5 +1,6 @@ import { Timeline, asyncReduce } from "@pnp/core"; import { expect } from "chai"; +import { pnpTest } from "../pnp-test.js"; const TestingMoments = { first: asyncReduce<(a: number) => Promise<[number]>>(), @@ -62,7 +63,7 @@ describe("Timeline", function () { return expect(h).to.eq(2); }); - it("Should process moments 2", async function () { + it("Should process moments 2", pnpTest("8267d3af-554d-44d8-8b00-e33ce7d93f1d", async function () { const tl = new TestTimeline(); @@ -78,9 +79,9 @@ describe("Timeline", function () { const h = await tl.go(0); return expect(h).to.eq(7); - }); + })); - it("Prepend works as expected", function () { + it("Prepend works as expected", pnpTest("890664f0-0e7f-4aa5-bc73-55fa4b05b27b", function () { const tl = new TestTimeline(); @@ -97,9 +98,9 @@ describe("Timeline", function () { expect(observers[0]).to.eq(f3); expect(observers[1]).to.eq(f1); expect(observers[2]).to.eq(f2); - }); + })); - it("Clear works as expected", function () { + it("Clear works as expected", pnpTest("66b43d34-7e34-4506-abc9-4d12b8286937", function () { const tl = new TestTimeline(); @@ -120,9 +121,9 @@ describe("Timeline", function () { const observers2 = tl.on.first.toArray(); expect(observers2).length(0); - }); + })); - it("Replace works as expected", function () { + it("Replace works as expected", pnpTest("b162d48e-2ddd-4b36-8fee-fc3c9ef18838", function () { const tl = new TestTimeline(); @@ -144,9 +145,9 @@ describe("Timeline", function () { expect(observers2).length(1); expect(observers2[0]).to.eq(f1); - }); + })); - it("Logging works as expected", function () { + it("Logging works as expected", pnpTest("0506ad5a-7d00-4f0e-b436-46c90faadd9d", function () { const tl = new TestTimeline(); @@ -161,9 +162,9 @@ describe("Timeline", function () { tl.log("Test 2", 0); expect(messages.length).to.eq(2); - }); + })); - it("Lifecycle works as expected", async function () { + it("Lifecycle works as expected", pnpTest("a7dda9ad-cb00-4ad8-b717-4de294e02ad2", async function () { const tl = new TestTimeline(); @@ -201,5 +202,5 @@ describe("Timeline", function () { expect(tracker[1]).to.eq(2); expect(tracker[2]).to.eq(3); expect(tracker[3]).to.eq(4); - }); + })); }); diff --git a/test/core/util.ts b/test/core/util.ts index 8c953374e..4a032bfeb 100644 --- a/test/core/util.ts +++ b/test/core/util.ts @@ -13,111 +13,122 @@ import { hOP, getHashCode, } from "@pnp/core"; +import { pnpTest } from "../pnp-test.js"; // tslint:disable:no-unused-expression describe("dateAdd", function () { - it("Add 5 Minutes", function () { + + it("Add 5 Minutes", pnpTest("e5eeda9b-2378-430c-a9d9-ac952c0b4f8e", function () { const testDate = new Date(); const checkDate = new Date(testDate.toLocaleString()); checkDate.setMinutes(testDate.getMinutes() + 5); expect(dateAdd(testDate, "minute", 5).getMinutes()).to.eq(checkDate.getMinutes()); - }); + })); - it("Add 2 Years", function () { + it("Add 2 Years", pnpTest("2a25ffc5-4f96-4f59-9a57-26ea74d1a3b5", function () { const testDate = new Date(); const checkDate = new Date(testDate.toLocaleString()); checkDate.setFullYear(testDate.getFullYear() + 2); expect(dateAdd(testDate, "year", 2).getFullYear()).to.eq(checkDate.getFullYear()); - }); + })); + }); describe("combine", function () { - it("Path (1)", function () { + + it("Path (1)", pnpTest("e8cedd77-c58d-4277-9465-6afa2e73adae", function () { expect(combine("/path/", "path2", "path3", "/path4")).to.eq("path/path2/path3/path4"); - }); + })); - it("Path (2)", function () { + it("Path (2)", pnpTest("1b9f2dc6-5b17-4573-8a65-2ef651b8972c", function () { expect(combine("http://site/path/", "/path4/page.aspx")).to.eq("http://site/path/path4/page.aspx"); - }); + })); - it("Path (3)", function () { + it("Path (3)", pnpTest("df90d9c6-c841-42f4-88d0-fb4d1a0451a5", function () { expect(combine(null, "path2", undefined, null, "/path4")).to.eq("path2/path4"); - }); + })); - it("Path (4)", function () { + it("Path (4)", pnpTest("b8564799-f0cb-4183-81a9-564e1480eba4", function () { expect(combine(null, "path2", undefined, "", null, "/path4")).to.eq("path2/path4"); - }); + })); - it("No Path", function () { + it("No Path", pnpTest("502a081f-144e-45c8-8115-c1ad4bc75d72", function () { expect(combine()).to.eq(""); - }); + })); + }); describe("getRandomString", function () { - it("Length 5", function () { + + it("Length 5", pnpTest("6c726b85-720a-4793-b5f6-2d302d16eb5b", function () { const j = getRandomString(5); expect(j).to.be.a("string"); expect(j).to.have.length(5); - }); + })); - it("Length 28", function () { + it("Length 28", pnpTest("26afbb93-8d8d-4f2a-a1c0-b3a0fb78c6bb", function () { const j = getRandomString(28); expect(j).to.be.a("string"); expect(j).to.have.length(28); - }); + })); + }); describe("getGUID", function () { - it("Test Pattern", function () { + + it("Test Pattern", pnpTest("78cd5f6d-d30a-4c0c-b44f-f55e34e39b06", function () { expect(getGUID()).to.match(/[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}/i); - }); + })); + }); describe("isFunc", function () { - it("True", function () { + + it("True", pnpTest("ff0020e6-0e1b-4b12-a4a1-8a4b2fc8fcdb", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc(function () { return; })).to.be.true; - }); + })); - it("False", function () { + it("False", pnpTest("ff0020e6-0e1b-4b12-a4a1-8a4b2fc8fcdb", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc({ val: 0 })).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc(null)).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc(undefined)).to.be.false; - }); + })); }); describe("objectDefinedNotNull", function () { - it("defined", function () { + it("defined", pnpTest("71a58271-6205-4a7b-b651-9322a36398cc", function () { return expect(objectDefinedNotNull({})).to.be.true; - }); + })); - it("null", function () { + it("null", pnpTest("56af5be3-06e1-41b9-8183-2a9d7654052b", function () { return expect(objectDefinedNotNull(null)).to.be.false; - }); + })); - it("undefined", function () { + it("undefined", pnpTest("65dcfc1f-1c3b-488d-9bc5-3a5dd36e06a3", function () { return expect(objectDefinedNotNull(undefined)).to.be.false; - }); + })); }); describe("isArray", function () { - it("True", function () { + + it("True", pnpTest("3ad9a949-f147-47a7-868c-e1ae0fc9d65e", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isArray([1, 2, 3, 4])).to.be.true; - }); + })); - it("False", function () { + it("False", pnpTest("d2bb66ab-b7ed-4e3d-828a-2044d4a4ffed", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isArray(null)).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions @@ -128,78 +139,89 @@ describe("isArray", function () { expect(isArray({})).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isArray(undefined)).to.be.false; - }); + })); + }); describe("isUrlAbsolute", function () { - it("Yes (1)", function () { + + it("Yes (1)", pnpTest("edc77eae-ddd3-427c-aae8-863e79583c05", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("https://something.com")).to.be.true; - }); + })); - it("Yes (2)", function () { + it("Yes (2)", pnpTest("25999d21-cc28-4582-bdb5-31fa59af1191", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("//something.com")).to.be.true; - }); + })); - it("Yes (3)", function () { + it("Yes (3)", pnpTest("32547e58-299a-4979-a875-6d2dfdf324cc", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("http://something.com")).to.be.true; - }); + })); - it("No (1)", function () { + it("No (1)", pnpTest("2ee70c05-0f90-47ce-a6cf-801bf459cfca", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("/sites/dev")).to.be.false; - }); + })); - it("No (2)", function () { + it("No (2)", pnpTest("7b6b7504-fd43-4c4d-ad65-e944a11148e9", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("sites/dev")).to.be.false; - }); + })); - it("Empty", function () { + it("Empty", pnpTest("38c0cfa1-e518-47e9-a09a-7e941516dfb0", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("")).to.be.false; - }); + })); + }); describe("stringIsNullOrEmpty", function () { - it("Yes (1)", function () { + + it("Yes (1)", pnpTest("2c88a924-49d4-4468-b4ed-47dc59341499", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(stringIsNullOrEmpty(null)).to.be.true; - }); + })); - it("Yes (2)", function () { + it("Yes (2)", pnpTest("146cfe8e-3e74-420b-bde7-feec421fb3a8", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(stringIsNullOrEmpty("")).to.be.true; - }); + })); - it("No", function () { + it("No", pnpTest("e843faac-0423-44ee-8206-00468296ea61", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(stringIsNullOrEmpty("not empty")).to.be.false; - }); + })); + }); describe("jsS", function () { + it("Sucess", function () { expect(jsS({ test: true })).to.eq("{\"test\":true}"); }); + }); describe("hOP", function () { - it("Success", function () { + + it("Success", pnpTest("f1d3a279-c51e-4c1b-a3d3-3d8ef3c747f6", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(hOP({ test: true }, "test")).to.be.true; - }); - it("Fail", function () { + })); + + it("Fail", pnpTest("d65fb0d9-be6e-4a3d-9ba9-44e85e8d6288", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(hOP({ test: true }, "nope")).to.be.false; - }); + })); }); describe("getHashCode", function () { - it("Success", function () { + + it("Success", pnpTest("dcd0ccfc-b4ff-4d9f-bd37-8a1b14d2baea", function () { expect(getHashCode("test string value")).to.be.a("number"); expect(getHashCode("test string value !@#$%^&*()_+{}<>,.?/'\"")).to.be.a("number"); - }); + })); + }); diff --git a/test/graph/batch.ts b/test/graph/batch.ts index ab6602144..69016324e 100644 --- a/test/graph/batch.ts +++ b/test/graph/batch.ts @@ -3,6 +3,7 @@ import "@pnp/graph/groups"; import "@pnp/graph/sites"; import { createBatch } from "@pnp/graph/batching"; import { expect } from "chai"; +import { pnpTest } from "../pnp-test.js"; describe("Batching", function () { @@ -13,7 +14,7 @@ describe("Batching", function () { } }); - it("Single Request", async function () { + it("Single Request", pnpTest("104a9d10-ef6f-485f-961e-45014147f52a", async function () { const order: number[] = []; const expected: number[] = [1, 2]; @@ -27,9 +28,9 @@ describe("Batching", function () { order.push(2); return expect(order.toString()).to.eql(expected.toString()); - }); + })); - it("Even # Requests", async function () { + it("Even # Requests", pnpTest("52bb031b-2a18-46e7-bb1b-8c0085812e0d", async function () { const order: number[] = []; const expected: number[] = [1, 2, 3]; @@ -48,9 +49,9 @@ describe("Batching", function () { order.push(3); return expect(order.toString()).to.eql(expected.toString()); - }); + })); - it("Odd # Requests", async function () { + it("Odd # Requests", pnpTest("0f5f9c29-7da8-483b-8c7d-4a6a9656bb92", async function () { const order: number[] = []; const expected: number[] = [1, 2, 3, 4]; @@ -72,9 +73,9 @@ describe("Batching", function () { order.push(4); return expect(order.toString()).to.eql(expected.toString()); - }); + })); - it("Should work with the same Queryable when properly cloned (Advanced)", async function () { + it("Should work with the same Queryable when properly cloned (Advanced)", pnpTest("76fbb5bf-dfc5-4230-a9df-ef1ecc2ee7a4", async function () { const users = this.pnp.graph.users; @@ -87,9 +88,9 @@ describe("Batching", function () { this.pnp.graph.users.using(batchedBehavior)(); return expect(execute()).to.eventually.be.fulfilled; - }); + })); - it("Should work with the same Queryable when properly cloned by factory (Advanced)", async function () { + it("Should work with the same Queryable when properly cloned by factory (Advanced)", pnpTest("d0ba8747-a776-4f4e-be09-6a6126dc1e06", async function () { const users = this.pnp.graph.users; @@ -101,9 +102,9 @@ describe("Batching", function () { Users(users).using(batchedBehavior)(); return expect(execute()).to.eventually.be.fulfilled; - }); + })); - it("Should fail with the same Queryable (Advanced)", async function () { + it("Should fail with the same Queryable (Advanced)", pnpTest("ca3ae3bb-1729-47d9-abea-e531cd7817dc", async function () { const users = this.pnp.graph.users; @@ -121,5 +122,6 @@ describe("Batching", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(p2).to.eventually.be.fulfilled; - }); + })); + }); diff --git a/test/graph/calendars.ts b/test/graph/calendars.ts index 68251730b..69bd1f0bc 100644 --- a/test/graph/calendars.ts +++ b/test/graph/calendars.ts @@ -5,6 +5,8 @@ import { HttpRequestError } from "@pnp/queryable"; import { stringIsNullOrEmpty } from "@pnp/core"; import getValidUser from "./utilities/getValidUser.js"; +// TODO:: test recording setup + describe("Calendar", function () { let testUserName = ""; diff --git a/test/graph/columns.ts b/test/graph/columns.ts index 161a9ab52..eaff39179 100644 --- a/test/graph/columns.ts +++ b/test/graph/columns.ts @@ -9,6 +9,7 @@ import { ISite } from "@pnp/graph/sites"; import { IContentType } from "@pnp/graph/content-types"; import { getRandomString } from "@pnp/core"; import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; +import { pnpTest } from "../pnp-test.js"; describe("Columns", function () { @@ -31,12 +32,16 @@ describe("Columns", function () { }, }; - before(async function () { + before(pnpTest("7fa03413-981c-4d51-be83-8b1b9155985a", async function () { if (!this.pnp.settings.enableWebTests) { this.skip(); } + const props = await this.props({ + templateName: getRandomString(5) + "Columns", + }); + site = await getTestingGraphSPSite(this); const ctTemplate = JSON.parse(JSON.stringify({ @@ -50,7 +55,7 @@ describe("Columns", function () { id: "0x0100CDB27E23CEF44850904C80BD666FA645", })); - ctTemplate.name += getRandomString(5) + "Columns"; + ctTemplate.name += props.templateName; const addCT = await site.contentTypes.add(ctTemplate); contentType = addCT.contentType; @@ -61,7 +66,7 @@ describe("Columns", function () { }); list = addList.list; - }); + })); after(async function () { if (list != null) { @@ -73,15 +78,16 @@ describe("Columns", function () { }); describe("Site", function () { - it("columns", async function () { + + it("columns", pnpTest("052a70b6-953b-4267-800d-900b0bf1539d", async function () { const columns = await site.columns(); expect(columns).to.be.an("array"); if (columns.length > 0) { expect(columns[0]).to.haveOwnProperty("id"); } - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("e2ebde42-c5a9-4301-9fdc-92dd711d5414", async function () { let passed = true; const columns = await site.columns(); if (columns.length > 0) { @@ -89,33 +95,50 @@ describe("Columns", function () { passed = (column.id === columns[0].id); } return expect(passed).is.true; - }); + })); + + it("add", pnpTest("7880c343-29a8-4c44-9fb3-4b39f4309c36", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Add", + }); - it("add", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); columnTemplate.name += "Add"; - columnTemplate.displayName += getRandomString(5) + "Add"; + columnTemplate.displayName += props.displayName; const c = await site.columns.add(columnTemplate); await site.columns.getById(c.data.id).delete(); return expect((c.data.name === columnTemplate.name)).to.be.true; - }); + })); + + it("update", pnpTest("8ce610b0-3139-4e2b-9d90-47ad43247250", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Update", + displayName: getRandomString(5) + "Update", + }); - it("update", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Update"; - columnTemplate.displayName += getRandomString(5) + "Update"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const newColumnName = `${columnTemplate.displayName}-CHANGED`; const c = await site.columns.add(columnTemplate); await site.columns.getById(c.data.id).update({ displayName: newColumnName }); const updateColumn = await site.columns.getById(c.data.id)(); await site.columns.getById(c.data.id).delete(); return expect((updateColumn.displayName === newColumnName)).to.be.true; - }); + })); + + it("delete", pnpTest("bcb9bafc-4d9c-40d3-a335-b6ff9650e25c", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Update", + displayName: getRandomString(5) + "Update", + }); - it("delete", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Delete"; - columnTemplate.displayName += getRandomString(5) + "Delete"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const c = await site.columns.add(columnTemplate); await site.columns.getById(c.data.id).delete(); let deletedColumn: ColumnDefinition = null; @@ -125,24 +148,30 @@ describe("Columns", function () { // do nothing } return expect(deletedColumn).to.be.null; - }); + })); }); describe("Content-Type", function () { let siteColumn; - const columnTemplateName = sampleColumn.name + getRandomString(5) + "SiteColumn"; + let columnTemplateName; - before(async function () { + before(pnpTest("7b7c0559-06c7-4c7d-881e-bfc33d47c31a", async function () { if (!this.pnp.settings.enableWebTests) { this.skip(); } + const props = await this.props({ + columnTemplateName: sampleColumn.name + getRandomString(5) + "SiteColumn", + }); + + columnTemplateName = props.columnTemplateName; + const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); columnTemplate.name = columnTemplateName; columnTemplate.displayName = columnTemplateName; const addSiteCT = await site.columns.add(columnTemplate); siteColumn = addSiteCT.column; - }); + })); after(async function () { if (siteColumn != null) { @@ -150,12 +179,12 @@ describe("Columns", function () { } }); - it("columns", async function () { + it("columns", pnpTest("0312da75-4067-4d63-bb2c-e5f0d35f4b53", async function () { const columns = await contentType.columns(); return expect(columns).to.be.an("array") && expect(columns[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("d518e3f7-566d-4404-8e97-6cea48d5b1d1", async function () { let passed = true; const columns = await contentType.columns(); if (columns.length > 0) { @@ -163,23 +192,23 @@ describe("Columns", function () { passed = (column.id === columns[0].id); } return expect(passed).is.true; - }); + })); - it("addRef", async function () { + it("addRef", pnpTest("9dd8c09e-9e07-42e2-ac2d-5685966d2aa0", async function () { const c = await contentType.columns.addRef(siteColumn); await contentType.columns.getById(c.data.id).delete(); return expect((c.data.name === columnTemplateName)).to.be.true; - }); + })); // Site column properties cannot be updated in content type. - it.skip("update", async function () { + it.skip("update", pnpTest("c3afb14e-3f42-48e8-9ea6-43be8d231762", async function () { const c = await contentType.columns.addRef(siteColumn); const updateColumnResults = await contentType.columns.getById(c.data.id).update({ propagateChanges: true }); await contentType.columns.getById(c.data.id).delete(); return expect((updateColumnResults.propagateChanges)).to.be.true; - }); + })); - it("delete", async function () { + it("delete", pnpTest("4d6e18c1-abe7-4cd4-a90e-1c1715d5e1ce", async function () { const c = await contentType.columns.addRef(siteColumn); await contentType.columns.getById(c.data.id).delete(); let deletedColumn: ColumnDefinition = null; @@ -189,16 +218,16 @@ describe("Columns", function () { // do nothing } return expect(deletedColumn).to.be.null; - }); + })); }); describe("List", function () { - it("columns", async function () { + it("columns", pnpTest("2b7ff4ba-7b59-49ad-9d98-cda8bec9a012", async function () { const columns = await list.columns(); return expect(columns).to.be.an("array") && expect(columns[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("1560f120-d7da-491a-b27b-48c7b7d124ca", async function () { let passed = true; const columns = await list.columns(); if (columns.length > 0) { @@ -206,33 +235,50 @@ describe("Columns", function () { passed = (column.id === columns[0].id); } return expect(passed).is.true; - }); + })); + + it("add", pnpTest("387b5fb8-14b7-4c9a-8719-f62bc2289780", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Add", + }); - it("add", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); columnTemplate.name += "Add"; - columnTemplate.displayName += getRandomString(5) + "Add"; + columnTemplate.displayName += props.displayName; const c = await list.columns.add(columnTemplate); await list.columns.getById(c.data.id).delete(); return expect((c.data.name === columnTemplate.name)).to.be.true; - }); + })); + + it("update", pnpTest("3827a66a-2f8b-4cd7-addb-b49eac258f45", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Update", + displayName: getRandomString(5) + "Update", + }); - it("update", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Update"; - columnTemplate.displayName += getRandomString(5) + "Update"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const newColumnName = `${columnTemplate.displayName}-CHANGED`; const c = await list.columns.add(columnTemplate); await list.columns.getById(c.data.id).update({ displayName: newColumnName }); const updateColumn = await list.columns.getById(c.data.id)(); await list.columns.getById(c.data.id).delete(); return expect((updateColumn.displayName === newColumnName)).to.be.true; - }); + })); + + it("delete", pnpTest("16650b92-045a-4bfe-8f37-a8a8856385f2", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Delete", + displayName: getRandomString(5) + "Delete", + }); - it("delete", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Delete"; - columnTemplate.displayName += getRandomString(5) + "Delete"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const c = await list.columns.add(columnTemplate); await list.columns.getById(c.data.id).delete(); let deletedColumn: ColumnDefinition = null; @@ -242,6 +288,6 @@ describe("Columns", function () { // do nothing } return expect(deletedColumn).to.be.null; - }); + })); }); }); diff --git a/test/graph/contacts.ts b/test/graph/contacts.ts index 43ccd17c4..817f41f9e 100644 --- a/test/graph/contacts.ts +++ b/test/graph/contacts.ts @@ -4,6 +4,8 @@ import "@pnp/graph/contacts"; import { HttpRequestError } from "@pnp/queryable"; import { getRandomString, stringIsNullOrEmpty } from "@pnp/core"; +// TODO:: make work with test recording + describe("Contacts", function () { let testUserName = ""; diff --git a/test/graph/content-types.ts b/test/graph/content-types.ts index 8e3cf65d4..0f04a3803 100644 --- a/test/graph/content-types.ts +++ b/test/graph/content-types.ts @@ -7,6 +7,7 @@ import { IList } from "@pnp/graph/lists"; import { ISite } from "@pnp/graph/sites"; import { getRandomString } from "@pnp/core"; import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; +import { pnpTest } from "../pnp-test.js"; describe("ContentTypes", function () { let site: ISite; @@ -23,21 +24,25 @@ describe("ContentTypes", function () { id: "0x0100CDB27E23CEF44850904C80BD666FA645", }; - before(async function () { + before(pnpTest("558cdcaf-dfe4-47e1-a310-7b1c4c9e5d1d", async function () { if (!this.pnp.settings.enableWebTests) { this.skip(); } + const props = await this.props({ + displayName: `PnPGraphTestContentTypes_${getRandomString(8)}`, + }); + site = await getTestingGraphSPSite(this); const listTmp = await site.lists.add({ - displayName: `PnPGraphTestContentTypes_${getRandomString(8)}`, + displayName: props.displayName, list: { "template": "genericList" }, }); list = site.lists.getById(listTmp.data.id); - }); + })); after(async function () { if (list != null) { @@ -47,12 +52,12 @@ describe("ContentTypes", function () { describe("Site", function () { - it("content types", async function () { + it("content types", pnpTest("adc47d1e-6b59-4287-a7f6-1fa42a0862e2", async function () { const ct = await site.contentTypes(); return expect(ct).to.be.an("array") && expect(ct[0]).to.haveOwnProperty("id"); - }); + })); - it("getById", async function () { + it("getById", pnpTest("ab0e1dc6-6387-404f-8acc-b8025d5aa049", async function () { let passed = true; const cts = await site.contentTypes(); if (cts.length > 0) { @@ -60,20 +65,25 @@ describe("ContentTypes", function () { passed = (ct.id === cts[0].id); } return expect(passed).is.true; - }); + })); - it("getCompatibleFromHub", async function () { + it("getCompatibleFromHub", pnpTest("42b30d81-10bf-490e-aaee-e8a2c67c8006", async function () { const cts = await site.contentTypes.getCompatibleHubContentTypes(); return expect(cts).to.be.an("array"); - }); + })); + + it("add", pnpTest("3e939430-6d79-45e9-92cf-1a296a2e0911", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Add", + }); - it("add", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "Add"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await site.contentTypes.getById(ct.data.id).delete(); return expect((ct.data.name === ctTemplate.name)).to.be.true; - }); + })); // potential long running function - not approrpriate for automated tests it.skip("addFromHub"); @@ -82,52 +92,77 @@ describe("ContentTypes", function () { it.skip("associateWithHub"); // Errors with ~ Metadata hub feature is disabled on this site. - it.skip("isPublished", async function () { + it.skip("isPublished", pnpTest("4c3b75f9-d46e-4ae4-a1b7-8ce7bb43009c", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteIsPublished", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteIsPublished"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); const isPublished = await ct.contentType.isPublished(); await site.contentTypes.getById(ct.data.id).delete(); return expect(isPublished).to.be.false; - }); + })); // Errors with ~ Metadata hub feature is disabled on this site. - it.skip("publish", async function () { + it.skip("publish", pnpTest("664acec7-ff46-4bbf-9352-16d0718767de", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SitePublish", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SitePublish"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await ct.contentType.publish(); const isPublished = await ct.contentType.isPublished(); await site.contentTypes.getById(ct.data.id).delete(); return expect(isPublished).to.be.true; - }); + })); // Errors with ~ Metadata hub feature is disabled on this site. - it.skip("unpublish", async function () { + it.skip("unpublish", pnpTest("28cd50ea-5672-48fc-9fc1-842c9d69688b", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteUnPublish", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteUnPublish"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await ct.contentType.publish(); await ct.contentType.unpublish(); const isPublished = await ct.contentType.isPublished(); await site.contentTypes.getById(ct.data.id).delete(); return expect(isPublished).to.be.false; - }); + })); + + it("update", pnpTest("41d3c22d-8632-4890-9ecf-7d0a367d739c", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteUpdate", + }); - it("update", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteUpdate"; + ctTemplate.name += props.name; const newContentTypeName = `${ctTemplate.name}-CHANGED`; const ct = await site.contentTypes.add(ctTemplate); await site.contentTypes.getById(ct.data.id).update({ name: newContentTypeName }); const updateContentType = await site.contentTypes.getById(ct.data.id)(); await site.contentTypes.getById(ct.data.id).delete(); return expect((updateContentType.name === newContentTypeName)).to.be.true; - }); + })); + + it("delete", pnpTest("50a499b1-b6b9-47f7-b14e-567c03ac77a2", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteDelete", + }); - it("delete", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteDelete"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await site.contentTypes.getById(ct.data.id).delete(); let deletedContentType: ContentType = null; @@ -137,16 +172,17 @@ describe("ContentTypes", function () { // do nothing } return expect(deletedContentType).to.be.null; - }); + })); }); describe("List", function () { - it("content types", async function () { + + it("content types", pnpTest("3ee007d0-e331-4842-bc8e-8251726d9d39", async function () { const ct = await list.contentTypes(); return expect(ct).to.be.an("array") && expect(ct[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("ab0abf2f-4ffe-4d37-af4b-c8bdb8f2a257", async function () { let passed = true; const cts = await list.contentTypes(); if (cts.length > 0) { @@ -154,29 +190,39 @@ describe("ContentTypes", function () { passed = (ct.id === cts[0].id); } return expect(passed).is.true; - }); + })); - it("getCompatibleFromHub", async function () { + it("getCompatibleFromHub", pnpTest("c74f5186-5aff-4b18-b5b7-97edcd4bd6c5", async function () { const cts = await list.contentTypes.getCompatibleHubContentTypes(); return expect(cts).to.be.an("array"); - }); + })); // potential long running function - not approrpriate for automated tests it.skip("addFromHub"); - it("addCopy", async function () { + it("addCopy", pnpTest("ef5ebb3f-f8f1-4b57-a977-c3ad359365ca", async function () { + + const props = await this.props({ + name: getRandomString(5) + "ListAddCopy", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "ListAddCopy"; + ctTemplate.name += props.name; const siteCT = await site.contentTypes.add(ctTemplate); const listCT = await list.contentTypes.addCopy(siteCT.contentType); await list.contentTypes.getById(listCT.data.id).delete(); await site.contentTypes.getById(siteCT.data.id).delete(); return expect((siteCT.data.name === listCT.data.name)).to.be.true; - }); + })); + + it("update", pnpTest("3add8b28-47ea-45a9-9db3-aa370e088f67", async function () { + + const props = await this.props({ + name: getRandomString(5) + "ListUpdate", + }); - it("update", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "ListUpdate"; + ctTemplate.name += props.name; const newContentTypeName = `${ctTemplate.displayName}-CHANGED`; const siteCT = await site.contentTypes.add(ctTemplate); const listCT = await list.contentTypes.addCopy(siteCT.contentType); @@ -185,11 +231,16 @@ describe("ContentTypes", function () { await list.contentTypes.getById(listCT.data.id).delete(); await site.contentTypes.getById(siteCT.data.id).delete(); return expect((updateContentType.name === newContentTypeName)).to.be.true; - }); + })); + + it("delete", pnpTest("5d8dc8f0-5220-400b-b990-0bcdfcd08594", async function () { + + const props = await this.props({ + name: getRandomString(5) + "ListDelete", + }); - it("delete", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "ListDelete"; + ctTemplate.name += props.name; const siteCT = await site.contentTypes.add(ctTemplate); const listCT = await list.contentTypes.addCopy(siteCT.contentType); await list.contentTypes.getById(listCT.data.id).delete(); @@ -201,6 +252,6 @@ describe("ContentTypes", function () { // do nothing } return expect(deletedContentType).to.be.null; - }); + })); }); }); diff --git a/test/graph/directoryobjects.ts b/test/graph/directoryobjects.ts index 9ed55e2ec..edcbf600d 100644 --- a/test/graph/directoryobjects.ts +++ b/test/graph/directoryobjects.ts @@ -5,103 +5,118 @@ import "@pnp/graph/directory-objects"; import { GroupType } from "@pnp/graph/groups"; import { getRandomString, getGUID, stringIsNullOrEmpty } from "@pnp/core"; import getValidUser from "./utilities/getValidUser.js"; +import { pnpTest } from "../pnp-test.js"; describe("Directory Objects", function () { let testUserName = ""; let testChildGroupID = ""; let testParentGroupID = ""; - const testGUID = getGUID(); - let userInfo = null; + let testGUID; + let userId = null; - before(async function () { + before(pnpTest("3adea3f7-de9b-4872-92c4-82f964a072a8", async function () { if (!this.pnp.settings.enableWebTests || stringIsNullOrEmpty(this.pnp.settings.testUser)) { this.skip(); } // Get a sample user - userInfo = await getValidUser.call(this); - testUserName = userInfo.userPrincipalName; + const userInfo = await getValidUser.call(this); + + const props = await this.props({ + groupName1: `TestGroup_${getRandomString(4)}`, + groupName2: `TestGroup_${getRandomString(4)}`, + userId: userInfo.id, + userName: userInfo.userPrincipalName, + testGuid: getGUID(), + }); + + testUserName = props.userName; + userId = props.userId; + testGUID = props.testGuid; // Create a test group to ensure we have a directory object - let groupName = `TestGroup_${getRandomString(4)}`; - let result = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Security, { + + let result = await this.pnp.graph.groups.add(props.groupName1, props.groupName1, GroupType.Security, { "members@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, ], "owners@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, ], }); testChildGroupID = result.data.id; - groupName = `TestGroup_${getRandomString(4)}`; - result = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Security, { + result = await this.pnp.graph.groups.add(props.groupName2, props.groupName2, GroupType.Security, { "members@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, "https://graph.microsoft.com/v1.0/groups/" + testChildGroupID, ], "owners@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, ], }); testParentGroupID = result.data.id; - }); + })); - it("delete", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const result = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Security, { + it("delete", pnpTest("e1d8a9b8-43c1-4c02-85b3-92ef980d0ee2", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); + + const result = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Security, { "members@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + userId, ], "owners@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + userId, ], }); const testDeleteGroupID = result.data.id; return expect(this.pnp.graph.groups.getById(testDeleteGroupID).delete()).eventually.be.fulfilled; - }); + })); - it("Get User Member Objects", async function () { + it("Get User Member Objects", pnpTest("ba2c72fb-d9f0-412d-988e-527d0ce9b7a6", async function () { const memberObjects = await this.pnp.graph.users.getById(testUserName).getMemberObjects(); return expect(memberObjects).contains(testChildGroupID); - }); + })); - it("Get Group Member Objects", async function () { + it("Get Group Member Objects", pnpTest("37fe45e5-5c9b-4b45-a8a5-bd8536ecb512", async function () { const memberObjects = await this.pnp.graph.groups.getById(testChildGroupID).getMemberObjects(true); return expect(memberObjects).contains(testParentGroupID); - }); + })); - it("Get User Member Groups", async function () { + it("Get User Member Groups", pnpTest("a66c2661-e9c1-4880-a5cf-f85c04c1fc09", async function () { const memberObjects = await this.pnp.graph.users.getById(testUserName).getMemberGroups(true); return expect(memberObjects).contains(testChildGroupID); - }); + })); - it("Get Group Member Objects", async function () { + it("Get Group Member Objects", pnpTest("a41f6893-7942-4584-a688-5cdef1304329", async function () { const memberObjects = await this.pnp.graph.groups.getById(testChildGroupID).getMemberGroups(); return expect(memberObjects).contains(testParentGroupID); - }); + })); - it("Check User Member Groups (1)", async function () { + it("Check User Member Groups (1)", pnpTest("fff79512-3b81-4b1f-8de2-c8c65ff3985e", async function () { const memberGroups = await this.pnp.graph.users.getById(testUserName).checkMemberGroups([testChildGroupID, testParentGroupID, testGUID]); return expect(memberGroups.length).is.equal(2); - }); + })); - it("Check User Member Groups (2)", async function () { + it("Check User Member Groups (2)", pnpTest("02172c11-b086-4fb8-a70b-216d24f17d3d", async function () { const memberGroups = await this.pnp.graph.groups.getById(testChildGroupID).checkMemberGroups([testChildGroupID, testParentGroupID, testGUID]); return expect(memberGroups.length).is.equal(1); - }); + })); - it("Get directory object by ID", async function () { + it("Get directory object by ID", pnpTest("501eef0b-1cb8-4b1e-b716-0876114f677c", async function () { const dirObj = await this.pnp.graph.directoryObjects.getById(testChildGroupID); return expect(dirObj).is.not.null; - }); + })); - it("Check MemberOf", async function () { + it("Check MemberOf", pnpTest("cfcd853b-8cba-4fea-8d1d-16afc35ba392", async function () { const memberObjects = await this.pnp.graph.users.getById(testUserName).memberOf(); return expect(memberObjects.length).greaterThan(0); - }); + })); // Remove the test data we created after(async function () { diff --git a/test/graph/groups.ts b/test/graph/groups.ts index b9704f59f..aefbba33a 100644 --- a/test/graph/groups.ts +++ b/test/graph/groups.ts @@ -2,6 +2,7 @@ import { getRandomString } from "@pnp/core"; import { expect } from "chai"; import { GroupType } from "@pnp/graph/groups"; import "@pnp/graph/sites/group"; +import { pnpTest } from "../pnp-test.js"; describe("Groups", function () { @@ -19,18 +20,26 @@ describe("Groups", function () { groupID = ""; }); - it("add", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + it("add", pnpTest("022e5336-56a1-4bd3-80a2-74139f386e40", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); + + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); const group = await groupAddResult.group(); groupID = groupAddResult.data.id; return expect(group.displayName).is.not.undefined; - }); + })); + + it("delete", pnpTest("c6d59c80-332b-4d6d-8dbd-54c111cdcf12", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); - it("delete", async function () { // Create a new group - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); // Delete the group // Potential Bug. Delete is only available off of getByID await this.pnp.graph.groups.getById(groupAddResult.data.id).delete(); @@ -44,21 +53,29 @@ describe("Groups", function () { } }); return expect(groupExists).is.not.true; - }); + })); + + it("getById", pnpTest("ea5ae8ab-570c-48fc-b01f-331f3e6ad366", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); - it("getById", async function () { // Create a new group - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); // Get the group by ID const group = await this.pnp.graph.groups.getById(groupAddResult.data.id); return expect(group).is.not.undefined; - }); + })); + + it("update", pnpTest("d1845967-2d71-4995-90e0-58e8967a249a", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); - it("update", async function () { // Create a new group - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); groupID = groupAddResult.data.id; // Update the display name of the group @@ -69,10 +86,10 @@ describe("Groups", function () { // Get the group to check and see if the names are different const group = await this.pnp.graph.groups.getById(groupID)(); - return expect(groupName === group.displayName).is.not.true; - }); + return expect(props.groupName === group.displayName).is.not.true; + })); - it("sites.root.sites", async function () { + it("sites.root.sites", pnpTest("ae59d162-bb17-40f0-b606-a9b5bab3ec6c", async function () { // Find an existing group // This has to be tested on existing groups. On a newly created group, this returns an error often // "Resource provisioning is in progress. Please try again.". This is expected as the team site provisioning takes a few seconds when creating a new group @@ -83,9 +100,9 @@ describe("Groups", function () { const sitesPromise = this.pnp.graph.groups.getById(grpID).sites.root.sites(); return expect(sitesPromise).to.eventually.be.fulfilled; - }); + })); - it("sites.root", async function () { + it("sites.root", pnpTest("b5fce16b-aa14-40e3-98c5-28a828050c04", async function () { // Find an existing group const groups = await this.pnp.graph.groups(); const grpID = groups[0].id; @@ -94,32 +111,7 @@ describe("Groups", function () { const root = await this.pnp.graph.groups.getById(grpID).sites.root(); return expect(root).is.not.null; - }); - - // it("addFavorite()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("removeFavorite()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("resetUnseenCount()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("subscribeByMail()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("unsubscribeByMail()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("getCalendarView(start: Date, end: Date)", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); + })); afterEach(async function () { if (groupID !== "") { diff --git a/test/graph/lists.ts b/test/graph/lists.ts index dec278374..fbfcfa71e 100644 --- a/test/graph/lists.ts +++ b/test/graph/lists.ts @@ -5,6 +5,7 @@ import { List } from "@microsoft/microsoft-graph-types"; import { ISite } from "@pnp/graph/sites"; import { getRandomString } from "@pnp/core"; import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; +import { pnpTest } from "../pnp-test.js"; describe("Lists", function () { let site: ISite; @@ -22,12 +23,12 @@ describe("Lists", function () { site = await getTestingGraphSPSite(this); }); - it("lists", async function () { + it("lists", pnpTest("016307d3-a0e3-4c8c-94e8-4f1c8566ffbd", async function () { const lists = await site.lists(); return expect(lists).to.be.an("array") && expect(lists[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("657e7fc0-bf7d-40ed-b903-d75fe0b91d65", async function () { let passed = true; const lists = await site.lists(); if (lists.length > 0) { @@ -35,30 +36,45 @@ describe("Lists", function () { passed = (list.id === lists[0].id); } return expect(passed).is.true; - }); + })); + + it("add", pnpTest("a5b3a404-53bb-4895-815d-6681cc36fe7f", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Add", + }); - it("add", async function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); - listTemplate.displayName += getRandomString(5) + "Add"; + listTemplate.displayName += props.displayName; const list = await site.lists.add(listTemplate); await site.lists.getById(list.data.id).delete(); return expect((list.data.displayName === listTemplate.displayName)).to.be.true; - }); + })); + + it("update", pnpTest("a386a85a-03ce-4846-8ca8-2472075694f5", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Update", + }); - it("update", async function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); - listTemplate.displayName += getRandomString(5) + "Update"; + listTemplate.displayName += props.displayName; const newListName = `${listTemplate.displayName}-CHANGED`; const list = await site.lists.add(listTemplate); await site.lists.getById(list.data.id).update({ displayName: newListName }); const updateList = await site.lists.getById(list.data.id)(); await site.lists.getById(list.data.id).delete(); return expect((updateList.displayName === newListName)).to.be.true; - }); + })); + + it("delete", pnpTest("3d070839-0713-4a3e-a718-f89bb378cbe1", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Delete", + }); - it("delete", async function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); - listTemplate.displayName += getRandomString(5) + "Delete"; + listTemplate.displayName += props.displayName; const list = await site.lists.add(listTemplate); await site.lists.getById(list.data.id).delete(); let deletedList: List = null; @@ -68,5 +84,5 @@ describe("Lists", function () { // do nothing } return expect(deletedList).to.be.null; - }); + })); }); diff --git a/test/pnp-test.ts b/test/pnp-test.ts index 6fc4ba607..2fc338275 100644 --- a/test/pnp-test.ts +++ b/test/pnp-test.ts @@ -15,6 +15,10 @@ interface IPnPTestFunc { export const PnPTestHeaderName = "X-PnP-TestId"; +// we use this to identify tests with duplicate ids, which will cause problems +// really just a safety measure for us +const idDupeTracker = []; + /** * Behavior used to inject the correct test id into the headers for each request * @@ -46,6 +50,12 @@ function PnPTestIdHeader(id: () => string): TimelinePipe { */ export function pnpTest(id: string, testFunc: (this: IPnPTestFuncThis) => any): IPnPTestFunc { + if (idDupeTracker.indexOf(id.toLowerCase()) > -1) { + throw Error(`Test ${id} is already in use.`); + } + + idDupeTracker.push(id.toLowerCase()); + return async function (this: IPnPTestFuncThis, ...args: any[]) { this.pnpid = id; diff --git a/test/test-recording.ts b/test/test-recording.ts index 88916868d..688fa3813 100644 --- a/test/test-recording.ts +++ b/test/test-recording.ts @@ -9,6 +9,9 @@ import { default as nodeFetch } from "node-fetch"; // TODO:: a way to record tests from the browser -> console.log what we would save in a file along with the generated filename +// PS to create Guids and put them on the clip board +// "pnpTest(""$(([guid]::NewGuid() | select Guid -expandproperty Guid | Out-String).Trim())"", " | Set-Clipboard + export interface IRecordingOptions { resolvedRecordingPath: string; resolvedTestSettingsPath: string;