Skip to content

Commit

Permalink
Fixing Presence Tests and return object from Presence type
Browse files Browse the repository at this point in the history
  • Loading branch information
bcameron1231 committed Sep 29, 2023
1 parent 976d673 commit 969f4e4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
28 changes: 21 additions & 7 deletions packages/graph/cloud-communications/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { Presence as IUserPresence } from "@microsoft/microsoft-graph-types";
import { DateTimeTimeZone, Presence as IUserPresence, ItemBody } from "@microsoft/microsoft-graph-types";
import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost } from "../graphqueryable.js";
import { defaultPath } from "../decorators.js";
import { body } from "@pnp/queryable";
Expand All @@ -15,17 +15,17 @@ export class _Presence extends _GraphInstance<IUserPresence> {
*
* @param presence Presence object to set the state of a user's presence session
*/
public async setPresence(presence: ISetPresenceOptions): Promise<ISetPresenceOptions> {
public async setPresence(presence: ISetPresenceOptions): Promise<void> {

const postBody = { ...presence };
return graphPost(Presence(this, "setPresence"), body(postBody));
}

/**
* Clear application presence session of a user. If it is the user's only presence session, the user's presence will change to Offline/Offline.
*
* @param sessionId Id of the application to clear presence
*/
* Clear application presence session of a user. If it is the user's only presence session, the user's presence will change to Offline/Offline.
*
* @param sessionId Id of the application to clear presence
*/
public async clearPresence(sessionId: string): Promise<void> {

const postBody = { sessionId };
Expand All @@ -36,7 +36,7 @@ export class _Presence extends _GraphInstance<IUserPresence> {
*
* @param presence Presence object to set as preferred availbility and activity status of a user
*/
public async setPreferredPresence(presence: IPresenceOptions): Promise<IPresenceOptions> {
public async setPreferredPresence(presence: IPresenceOptions): Promise<void> {

const postBody = { ...presence };
return graphPost(Presence(this, "setUserPreferredPresence"), body(postBody));
Expand All @@ -49,6 +49,15 @@ export class _Presence extends _GraphInstance<IUserPresence> {
return graphPost(Presence(this, "clearUserPreferredPresence"));
}

/**
* Set a presence status message for a user
*
*/
public async setStatusMessage(message: IPresenceStatusMessage): Promise<void> {
const postBody = { statusMessage: {...message} };
return graphPost(Presence(this, "setStatusMessage"), body(postBody));
}

}
export interface IPresence extends _Presence { }
export const Presence = graphInvokableFactory<IPresence>(_Presence);
Expand Down Expand Up @@ -76,3 +85,8 @@ export interface IPresenceOptions extends IUserPresence{
export interface ISetPresenceOptions extends IPresenceOptions {
sessionId: string;
}

export interface IPresenceStatusMessage {
message: ItemBody;
expiryDateTime: DateTimeTimeZone;
}

Check failure on line 92 in packages/graph/cloud-communications/types.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Newline required at end of file but not found
32 changes: 22 additions & 10 deletions test/graph/cloud-communications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,44 @@ describe("Cloud-Communications", function () {
});

Check failure on line 29 in test/graph/cloud-communications.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Trailing spaces not allowed
it("Set User Presence", async function () {
const presence = await this.pnp.graph.users.getById(testUserId).presence.setPresence({
return expect(this.pnp.graph.users.getById(testUserId).presence.setPresence({
availability: "Busy",
activity:"InACall",
sessionId: sessionId,
expirationDuration: "PT5M",
});
return expect(presence.availability).equals("Busy");
})).eventually.be.fulfilled;
});

it("Clear User Presence", async function () {
const presence = await this.pnp.graph.users.getById(testUserId).presence.clearPresence(sessionId);
return true;
return expect(this.pnp.graph.users.getById(testUserId).presence.clearPresence(sessionId)).eventually.be.fulfilled;
});

it("Set User Preferred Presence", async function () {
const presence = await this.pnp.graph.users.getById(testUserId).presence.setPreferredPresence({
return expect(this.pnp.graph.users.getById(testUserId).presence.setPreferredPresence({
availability: "Available",
activity:"Available",
expirationDuration: "PT5M",
});
return expect(presence.availability).equals("Available");
})).eventually.be.fulfilled;
});

it("Clear User Preferred Presence", async function () {
const presence = await this.pnp.graph.users.getById(testUserId).presence.clearPreferredPresence();
return true;
return expect(this.pnp.graph.users.getById(testUserId).presence.clearPreferredPresence()).eventually.be.fulfilled;
});

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"

Check failure on line 62 in test/graph/cloud-communications.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Missing trailing comma
},
expiryDateTime:{
dateTime: date.toISOString(),
timeZone: 'Pacific Standard Time'

Check failure on line 66 in test/graph/cloud-communications.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Strings must use doublequote

Check failure on line 66 in test/graph/cloud-communications.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Missing trailing comma
}

Check failure on line 67 in test/graph/cloud-communications.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Missing trailing comma
})).eventually.be.fulfilled;
});

Check failure on line 70 in test/graph/cloud-communications.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Trailing spaces not allowed
});

0 comments on commit 969f4e4

Please sign in to comment.