From 0f69cd88541f21f5819eb52592ee3dece4337ac0 Mon Sep 17 00:00:00 2001 From: Julie Turner Date: Thu, 18 Apr 2024 17:59:38 +0000 Subject: [PATCH] Bug fixes for tests --- packages/graph/mail/users.ts | 8 +++--- test/graph/batch.ts | 42 ++++++++++++++++++++++++------- test/graph/contacts.ts | 2 +- test/graph/files.ts | 5 ++-- test/graph/group-conversations.ts | 17 +++++-------- test/graph/mail-folders.ts | 1 + test/graph/mail-mailbox.ts | 1 + test/graph/mail-messages.ts | 9 ++++--- test/graph/mail-rules.ts | 1 + test/sp/files.ts | 1 + test/sp/site-groups.ts | 22 ++++++++++------ 11 files changed, 71 insertions(+), 38 deletions(-) diff --git a/packages/graph/mail/users.ts b/packages/graph/mail/users.ts index af84b9d85..482876f09 100644 --- a/packages/graph/mail/users.ts +++ b/packages/graph/mail/users.ts @@ -14,7 +14,7 @@ declare module "../users/types" { readonly mailFolders: IMailFolders; readonly outlook: IOutlook; readonly focusedInboxOverrides: IFocusedInboxOverrides; - sendMail(message: IMessageType): Promise; + sendMail(message: IMessageType, saveToSentItems?: boolean): Promise; translateExchangeIds(translateExchangeIds: ITranslateExchangeIds): Promise; } interface IUser { @@ -23,7 +23,7 @@ declare module "../users/types" { readonly mailFolders: IMailFolders; readonly outlook: IOutlook; readonly focusedInboxOverrides: IFocusedInboxOverrides; - sendMail(message: IMessageType): Promise; + sendMail(message: IMessageType, saveToSentItems?: boolean): Promise; translateExchangeIds(translateExchangeIds: ITranslateExchangeIds): Promise; } } @@ -34,8 +34,8 @@ addProp(_User, "mailFolders", MailFolders); addProp(_User, "outlook", Outlook); addProp(_User, "focusedInboxOverrides", FocusedInboxOverrides, "inferenceClassification/overrides"); -_User.prototype.sendMail = function (this: _User, message: IMessageType): Promise { - return graphPost(User(this, "sendMail"), body(message)); +_User.prototype.sendMail = function (this: _User, message: IMessageType, saveToSentItems = true): Promise { + return graphPost(User(this, "sendMail"), body({message, saveToSentItems})); }; /** diff --git a/test/graph/batch.ts b/test/graph/batch.ts index 69016324e..1a137cb61 100644 --- a/test/graph/batch.ts +++ b/test/graph/batch.ts @@ -75,6 +75,7 @@ describe("Batching", function () { return expect(order.toString()).to.eql(expected.toString()); })); + // This logs to the console when it passes, ignore those messages 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,16 @@ describe("Batching", function () { this.pnp.graph.users.using(batchedBehavior)(); this.pnp.graph.users.using(batchedBehavior)(); - return expect(execute()).to.eventually.be.fulfilled; + let success = true; + try { + await execute(); + } catch (err) { + success = false; + } + return expect(success).to.be.true; })); + // This logs to the console when it passes, ignore those messages 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 +109,16 @@ describe("Batching", function () { Users(users).using(batchedBehavior)(); Users(users).using(batchedBehavior)(); - return expect(execute()).to.eventually.be.fulfilled; + let success = true; + try { + await execute(); + } catch (err) { + success = false; + } + return expect(success).to.be.true; })); + // This logs to the console when it passes, ignore those messages it("Should fail with the same Queryable (Advanced)", pnpTest("ca3ae3bb-1729-47d9-abea-e531cd7817dc", async function () { const users = this.pnp.graph.users; @@ -113,15 +128,24 @@ describe("Batching", function () { users(); - const p = users(); - - const p2 = execute(); + let pSuccess = false; + try { + await users(); + pSuccess = true; + } catch (err) { + // do nothing + } - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - expect(p).to.eventually.be.rejected; + let p2Success = true; + try { + await execute(); + } catch (err) { + // do nothing + p2Success = false; + } + const success = (!pSuccess && p2Success); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - expect(p2).to.eventually.be.fulfilled; + return expect(success).to.be.true; })); }); diff --git a/test/graph/contacts.ts b/test/graph/contacts.ts index 7c772a925..c62d8f0b7 100644 --- a/test/graph/contacts.ts +++ b/test/graph/contacts.ts @@ -6,7 +6,7 @@ import { getRandomString, stringIsNullOrEmpty } from "@pnp/core"; // TODO:: make work with test recording -describe.only("Contacts", function () { +describe("Contacts", function () { let testUserName = ""; let testContactID = ""; diff --git a/test/graph/files.ts b/test/graph/files.ts index 9e3a40c79..c2bf8e77d 100644 --- a/test/graph/files.ts +++ b/test/graph/files.ts @@ -64,8 +64,6 @@ describe("Drive", function () { return expect(list).is.not.null; }); - - // TODO: Failing with Timeout it("Get Recent Drive Items", async function () { if (stringIsNullOrEmpty(driveId)) { this.skip(); @@ -233,6 +231,7 @@ describe("Drive", function () { return expect(thumbnails).is.not.null; }); + // This logs to the console when it passes, ignore those messages it("Delete Drive Item", async function () { if (stringIsNullOrEmpty(driveId)) { this.skip(); @@ -254,6 +253,7 @@ describe("Drive", function () { return expect(driveItemId).to.be.null; }); + // This logs to the console when it passes, ignore those messages it("Permanently Delete Drive Item", async function () { if (stringIsNullOrEmpty(driveId)) { this.skip(); @@ -349,7 +349,6 @@ describe("Drive", function () { return expect(driveItemUpdate.name).to.eq(testFileName2); }); - // TODO: Failing timeout it("Convert Drive Item", async function () { if (stringIsNullOrEmpty(driveId)) { this.skip(); diff --git a/test/graph/group-conversations.ts b/test/graph/group-conversations.ts index 650ee9369..28dc4edc4 100644 --- a/test/graph/group-conversations.ts +++ b/test/graph/group-conversations.ts @@ -11,7 +11,6 @@ import { import { getRandomString } from "@pnp/core"; describe("Group Conversations", function () { - let testUserName = ""; let groupId = ""; const draftPost: IPostType = { @@ -38,21 +37,15 @@ describe("Group Conversations", function () { before(async function () { - if (!this.pnp.settings.enableWebTests) { + if (!this.pnp.settings.enableWebTests || !this.pnp.settings.testGroupId) { this.skip(); } const userInfo = await getValidUser.call(this); - testUserName = userInfo.userPrincipalName; draftPost.from.emailAddress.address = userInfo.userPrincipalName; draftPost.from.emailAddress.name = userInfo.displayName; postForwardInfo.toRecipients[0].emailAddress.address = userInfo.userPrincipalName; postForwardInfo.toRecipients[0].emailAddress.name = userInfo.displayName; - const groups = await this.pnp.graph.users.getById(testUserName).joinedTeams(); - if (groups.length > 0) { - groupId = groups[0].id; - } else { - this.skip(); - } + groupId = this.pnp.settings.testGroupId; }); describe("Group Conversations", function () { @@ -99,7 +92,8 @@ describe("Group Conversations", function () { return expect(post).to.have.property("id"); }); - it("post reply", async function () { + // Even though docs say you can do this with app permissions throwing a 403, that said conversations do not support app permissions so it feels like a bug in the docs. + it.skip("post reply", async function () { const conversations = await this.pnp.graph.groups.getById(groupId).conversations(); const convThreads = await this.pnp.graph.groups.getById(groupId).conversations.getById(conversations[0].id).threads(); const threadPost = await this.pnp.graph.groups.getById(groupId).conversations.getById(conversations[0].id).threads.getById(convThreads[0].id).posts(); @@ -111,7 +105,8 @@ describe("Group Conversations", function () { return expect(reply).to.have.property("id"); }); - it("post forward", async function () { + // Even though docs say you can do this with app permissions throwing a 403, that said conversations do not support app permissions so it feels like a bug in the docs. + it.skip("post forward", async function () { let success = false; const conversations = await this.pnp.graph.groups.getById(groupId).conversations(); const convThreads = await this.pnp.graph.groups.getById(groupId).conversations.getById(conversations[0].id).threads(); diff --git a/test/graph/mail-folders.ts b/test/graph/mail-folders.ts index 22db3b6e0..7b09a1f03 100644 --- a/test/graph/mail-folders.ts +++ b/test/graph/mail-folders.ts @@ -113,6 +113,7 @@ describe("Mail: Folders", function () { return expect(success).to.be.true; }); + // This logs to the console when it passes, ignore those messages it("Mail: Folder Delete", async function () { const f: IMailFolder = JSON.parse(JSON.stringify(draftFolder)); f.displayName = `${testFolderName} ${getRandomString(8)}`; diff --git a/test/graph/mail-mailbox.ts b/test/graph/mail-mailbox.ts index e8229d37e..b26cba65a 100644 --- a/test/graph/mail-mailbox.ts +++ b/test/graph/mail-mailbox.ts @@ -134,6 +134,7 @@ describe("Mail: Mailbox", function () { return expect(success).to.be.true; }); + // This logs to the console when it passes, ignore those messages it("Mailbox: Delete Focused Inbox Override", async function () { const f: InferenceClassificationOverride = JSON.parse(JSON.stringify(override)); f.senderEmailAddress.name = `${testName} ${getRandomString(8)}`; diff --git a/test/graph/mail-messages.ts b/test/graph/mail-messages.ts index aa30fecdf..50b69b161 100644 --- a/test/graph/mail-messages.ts +++ b/test/graph/mail-messages.ts @@ -97,6 +97,7 @@ describe("Mail: Messages", function () { return expect(success).to.be.true; }); + // This logs to the console when it passes, ignore those messages it("Mail: Delete Message", async function () { const m = JSON.parse(JSON.stringify(draftMessage)); const draft = await user.messages.add(m); @@ -162,7 +163,7 @@ describe("Mail: Messages", function () { m.subject = `PnPjs Test Message ${getRandomString(8)}`; let success = false; try{ - await user.sendMail(m); + await user.sendMail(m, false); success = true; }catch(err){ // do nothing @@ -170,7 +171,8 @@ describe("Mail: Messages", function () { return success; }); - it("Mail: Create Draft Reply Message", async function () { + // Cannot guarantee that there is email message in the inbox suitable to reply to + it.skip("Mail: Create Draft Reply Message", async function () { const inboxMessage = await user.mailFolders.getById(inboxFolder).messages.top(1)(); if (inboxMessage.length === 1) { let success = false; @@ -189,7 +191,8 @@ describe("Mail: Messages", function () { // Skipping because it would possibly send an email to someone who didn't expect it }); - it("Mail: Create Draft Reply-All Message", async function () { + // Cannot guarantee that there is email message in the inbox suitable to reply to + it.skip("Mail: Create Draft Reply-All Message", async function () { const inboxMessage = await user.mailFolders.getById(inboxFolder).messages.top(1)(); if (inboxMessage.length === 1) { let success = false; diff --git a/test/graph/mail-rules.ts b/test/graph/mail-rules.ts index aa98a6003..2926fb78e 100644 --- a/test/graph/mail-rules.ts +++ b/test/graph/mail-rules.ts @@ -89,6 +89,7 @@ describe("Mail: Rules", function () { return expect(success).to.be.true; }); + // This logs to the console when it passes, ignore those messages it("Mail: Rule Delete", async function () { const r = JSON.parse(JSON.stringify(draftRule)); r.displayName = `PnPjs Test Rule ${getRandomString(8)}`; diff --git a/test/sp/files.ts b/test/sp/files.ts index 62036b643..0adb49c82 100644 --- a/test/sp/files.ts +++ b/test/sp/files.ts @@ -91,6 +91,7 @@ describe("Files", function () { expect(file.Name).to.eq(name); }); + // TODO: This is an ArrayBuffer but the addChunked method doesn't seem to support that when getting a readable stream, needs work. it("addChunked", async function () { const name = `Testing Chunked - ${getRandomString(4)}.jpg`; diff --git a/test/sp/site-groups.ts b/test/sp/site-groups.ts index ed1c3fc31..f98dba0c2 100644 --- a/test/sp/site-groups.ts +++ b/test/sp/site-groups.ts @@ -43,13 +43,20 @@ describe("SiteGroups", function () { }); // requires Custom Scripts to be enabled. Set-PnPSite -Identity -NoScriptSite $false - it("createDefaultAssociatedGroups()", async function () { + // Skipping as "custom scripts" feature disabled as of March 2024 + it.skip("createDefaultAssociatedGroups()", async function () { await this.pnp.sp.web.ensureUser(this.pnp.settings.testUser); const groupName = `TestGroup_${getRandomString(4)}`; - return expect(this.pnp.sp.web.createDefaultAssociatedGroups(groupName, - this.pnp.settings.testUser, - false, - false)).to.be.eventually.fulfilled; + let sucess = true; + try { + await this.pnp.sp.web.createDefaultAssociatedGroups(groupName, + this.pnp.settings.testUser, + false, + false); + } catch (err) { + sucess = false; + } + return expect(sucess).to.be.true; }); }); @@ -57,9 +64,10 @@ describe("SiteGroups", function () { return expect(this.pnp.sp.web.siteGroups.getById(newGroup.Id)()); }); - it("add()", function () { + it("add()", async function () { const newGroupTitle = `test_add_new_sitegroup_${getRandomString(8)}`; - return expect(this.pnp.sp.web.siteGroups.add({ "Title": newGroupTitle })).to.be.eventually.fulfilled; + const newGroup = await this.pnp.sp.web.siteGroups.add({ "Title": newGroupTitle }); + return expect(newGroup.Title).to.equal(newGroupTitle); }); it("getByName()", function () {