Skip to content

Commit

Permalink
Merge pull request #3000 from juliemturner/version-4
Browse files Browse the repository at this point in the history
V4 Test Updates
  • Loading branch information
juliemturner authored Apr 18, 2024
2 parents ad824a4 + 0f69cd8 commit 6731210
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 92 deletions.
1 change: 1 addition & 0 deletions docs/graph/cloud-communications.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import "@pnp/graph/cloud-communications";

const graph = graphfi(...);

// Session ID is the Application's client id
const presenceMe = await graph.me.presence.setPresence(
availability: "Busy",
activity:"InACall",
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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;
}));

});
95 changes: 61 additions & 34 deletions test/graph/cloud-communications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "@pnp/graph/users";
import "@pnp/graph/cloud-communications";
import { stringIsNullOrEmpty } from "@pnp/core";


describe("Cloud-Communications", function () {
let testUserId = "";
let sessionId = "";
Expand All @@ -13,59 +12,87 @@ describe("Cloud-Communications", function () {
if (!this.pnp.settings.enableWebTests || stringIsNullOrEmpty(this.pnp.settings.testUser)) {
this.skip();
}
testUserId = (await this.pnp.graph.users.getById(this.pnp.settings.testUser.substring(this.pnp.settings.testUser.lastIndexOf("|") + 1))()).id;
sessionId = this.pnp.settings.graph.id;
testUserId = (await this.pnp.graph.users.getById(this.pnp.settings.testUser.substring(this.pnp.settings.testUser.lastIndexOf("|") + 1))()).id;
sessionId = this.pnp.settings.graph.msal.init.auth.clientId;
});

it.skip("Get User Presence", async function () {
it("Get User Presence", async function () {
const presence = await this.pnp.graph.users.getById(testUserId).presence();
return expect(presence).is.not.null;
});

it.skip("Get Presence for Multiple Users", async function () {
const presence = await this.pnp.graph.communications.getPresencesByUserId([testUserId,testUserId]);
return expect(presence.length).is.equals(2);
it("Get Presence for Multiple Users", async function () {
const presence = await this.pnp.graph.communications.getPresencesByUserId([testUserId]);
return expect(presence.length).is.equals(1);
});

it("Set User Presence", async function () {
return expect(this.pnp.graph.users.getById(testUserId).presence.setPresence({
availability: "Busy",
activity:"InACall",
sessionId: sessionId,
expirationDuration: "PT5M",
})).eventually.be.fulfilled;
let success = true;
try {
await this.pnp.graph.users.getById(testUserId).presence.setPresence({
availability: "Busy",
activity: "InACall",
sessionId: sessionId,
expirationDuration: "PT5M",
});
} catch (err) {
success = false;
}
return expect(success).to.be.true;
});

it("Clear User Presence", async function () {
return expect(this.pnp.graph.users.getById(testUserId).presence.clearPresence(sessionId)).eventually.be.fulfilled;
let success = true;
try {
await this.pnp.graph.users.getById(testUserId).presence.clearPresence(sessionId);
} catch (err) {
success = false;
}
return expect(success).to.be.true;
});

it("Set User Preferred Presence", async function () {
return expect(this.pnp.graph.users.getById(testUserId).presence.setPreferredPresence({
availability: "Available",
activity:"Available",
expirationDuration: "PT5M",
})).eventually.be.fulfilled;
let success = true;
try {
await this.pnp.graph.users.getById(testUserId).presence.setPreferredPresence({
availability: "Available",
activity: "Available",
expirationDuration: "PT5M",
});
} catch (err) {
success = false;
}
return expect(success).to.be.true;
});

it("Clear User Preferred Presence", async function () {
return expect(this.pnp.graph.users.getById(testUserId).presence.clearPreferredPresence()).eventually.be.fulfilled;
let success = true;
try {
await this.pnp.graph.users.getById(testUserId).presence.clearPreferredPresence();
} catch (err) {
success = false;
}
return expect(success).to.be.true;
});

it("Set User Status Message", async function () {
const date: Date = new Date();
date.setDate(date.getDate() + 1);

return expect(this.pnp.graph.users.getById(testUserId).presence.setStatusMessage({
message:{
content: "Test Sample Message",
contentType: "text",
},
expiryDateTime:{
dateTime: date.toISOString(),
timeZone: "Pacific Standard Time",
},
})).eventually.be.fulfilled;
let success = true;
try {
const date: Date = new Date();
date.setDate(date.getDate() + 1);
await this.pnp.graph.users.getById(testUserId).presence.setStatusMessage({
message: {
content: "Test Sample Message",
contentType: "text",
},
expiryDateTime: {
dateTime: date.toISOString(),
timeZone: "Pacific Standard Time",
},
});
} catch (err) {
success = false;
}
return expect(success).to.be.true;
});

});
28 changes: 19 additions & 9 deletions test/graph/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ describe("Contacts", function () {
await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id).update({ birthday: "1986-05-30" });
const contact2 = await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id)();
// Clean up the added contact
await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id).delete();
try {
await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id).delete();
} catch (err) {
console.log(err.message);
}
return expect(contact2.birthday).equals("1986-05-30T11:59:00Z");
});

// This logs to the console when it passes, ignore those messages
it("Delete Contact", async function () {
// Add a contact that we can then delete
const testContactName = `TestUser_${getRandomString(4)}`;
Expand All @@ -105,15 +110,15 @@ describe("Contacts", function () {
let deletedUserFound = false;

try {

// If we try to find a user that doesn"t exist this returns a 404
// This passes the first time through, expecting it to fail on second pass.
// If we try to find a user that doesn't exist this returns a 404
await this.pnp.graph.users.getById(testUserName).contacts.getById(contact.id)();
deletedUserFound = true;

} catch (e) {
if (e?.isHttpRequestError) {
if ((<HttpRequestError>e).status === 404) {
console.error((<HttpRequestError>e).statusText);
// do nothing
}
} else {
console.log(e.message);
Expand Down Expand Up @@ -154,7 +159,7 @@ describe("Contacts", function () {
});

it("Update Contact Folder", async function () {
const folderDisplayName = "Folder_Updated" + getRandomString(4);
const folderDisplayName = `Folder_Updated_${getRandomString(4)}`;
let folderId = null;
let folderAfterUpdate = null;
try {
Expand All @@ -168,12 +173,17 @@ describe("Contacts", function () {
} finally {
// Clean up the added contact
if (folderId != null) {
await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folderId).delete();
try {
await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folderId).delete();
} catch (err) {
console.log(err.message);
}
}
}
return expect(folderAfterUpdate?.displayName).equals(folderDisplayName);
});

// This logs to the console when it passes, ignore those messages
it("Delete Contact Folder", async function () {
// Add a folder that we can then delete
const testFolderName = `TestFolder_${getRandomString(4)}`;
Expand All @@ -182,15 +192,15 @@ describe("Contacts", function () {
let deletedFolderFound = false;

try {

// If we try to find a folder that doesn"t exist this returns a 404
// This passes the first time through, expecting it to fail on second pass.
// If we try to find a folder that doesn't exist this returns a 404
await this.pnp.graph.users.getById(testUserName).contactFolders.getById(folder.id)();
deletedFolderFound = true;

} catch (e) {
if (e?.isHttpRequestError) {
if ((<HttpRequestError>e).status === 404) {
console.error((<HttpRequestError>e).statusText);
// do nothing
}
} else {
console.log(e.message);
Expand Down
Loading

0 comments on commit 6731210

Please sign in to comment.