Skip to content

Commit

Permalink
Bug fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julie Turner committed Apr 18, 2024
1 parent 2b8111c commit 0f69cd8
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 38 deletions.
8 changes: 4 additions & 4 deletions packages/graph/mail/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare module "../users/types" {
readonly mailFolders: IMailFolders;
readonly outlook: IOutlook;
readonly focusedInboxOverrides: IFocusedInboxOverrides;
sendMail(message: IMessageType): Promise<void>;
sendMail(message: IMessageType, saveToSentItems?: boolean): Promise<void>;
translateExchangeIds(translateExchangeIds: ITranslateExchangeIds): Promise<ITranslateExchangeIdsResponse[]>;
}
interface IUser {
Expand All @@ -23,7 +23,7 @@ declare module "../users/types" {
readonly mailFolders: IMailFolders;
readonly outlook: IOutlook;
readonly focusedInboxOverrides: IFocusedInboxOverrides;
sendMail(message: IMessageType): Promise<void>;
sendMail(message: IMessageType, saveToSentItems?: boolean): Promise<void>;
translateExchangeIds(translateExchangeIds: ITranslateExchangeIds): Promise<ITranslateExchangeIdsResponse[]>;
}
}
Expand All @@ -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<void> {
return graphPost(User(this, "sendMail"), body(message));
_User.prototype.sendMail = function (this: _User, message: IMessageType, saveToSentItems = true): Promise<void> {
return graphPost(User(this, "sendMail"), body({message, saveToSentItems}));
};

/**
Expand Down
42 changes: 33 additions & 9 deletions test/graph/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}));

});
2 changes: 1 addition & 1 deletion test/graph/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
5 changes: 2 additions & 3 deletions test/graph/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 6 additions & 11 deletions test/graph/group-conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { getRandomString } from "@pnp/core";

describe("Group Conversations", function () {
let testUserName = "";
let groupId = "";

const draftPost: IPostType = {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/graph/mail-folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand Down
1 change: 1 addition & 0 deletions test/graph/mail-mailbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand Down
9 changes: 6 additions & 3 deletions test/graph/mail-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -162,15 +163,16 @@ 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
}
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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/graph/mail-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand Down
1 change: 1 addition & 0 deletions test/sp/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
22 changes: 15 additions & 7 deletions test/sp/site-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,31 @@ describe("SiteGroups", function () {
});

// requires Custom Scripts to be enabled. Set-PnPSite -Identity <SiteURL> -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;
});
});

it("getById()", async 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 () {
Expand Down

0 comments on commit 0f69cd8

Please sign in to comment.