Skip to content

Commit

Permalink
Merge branch 'version-4' into version-4
Browse files Browse the repository at this point in the history
  • Loading branch information
juliemturner authored Mar 18, 2024
2 parents 44400aa + deb67b1 commit e5e7ae7
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 174 deletions.
80 changes: 40 additions & 40 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/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export class _Message extends _GraphInstance<IMessageType> {
* Create a draft response
*
* @param response (optional) The body of the response message
* If using JSON provide either comment: string or message: IMessageType.
* If using JSON, do not provide any payload, you will get an error.
* If using MIME format, provide the MIME content with the applicable Internet message headers, all encoded in base64 format.
* @param timeZone (optional) The time zone to use when creating the draft.
* Only use when providing a JSON message.
*/
public async createReply(response?: any, timeZone?: TimeZoneInformation): Promise<IMessageType> {
public async createReply(response?: string, timeZone?: TimeZoneInformation): Promise<IMessageType> {
return (await mailResponse(this, "createReply", response, timeZone)) as IMessageType;
}

Expand All @@ -71,12 +71,12 @@ export class _Message extends _GraphInstance<IMessageType> {
* Create a draft response message to all
*
* @param response (optional) The body of the response message
* If using JSON provide either comment: string or message: IMessageType.
* If using JSON, do not provide any payload, you will get an error.
* If using MIME format, provide the MIME content with the applicable Internet message headers, all encoded in base64 format.
* @param timeZone (optional) The time zone to use when creating the draft.
* Only use when providing a JSON message.
*/
public async createReplyAll(response?: any, timeZone?: TimeZoneInformation): Promise<IMessageType> {
public async createReplyAll(response?: string, timeZone?: TimeZoneInformation): Promise<IMessageType> {
return (await mailResponse(this, "createReplyAll", response, timeZone)) as IMessageType;
}

Expand Down
72 changes: 44 additions & 28 deletions test/graph/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import { List } from "@microsoft/microsoft-graph-types";
import { getRandomString, stringIsNullOrEmpty } from "@pnp/core";
import { IAnalyticsOptions } from "@pnp/graph/analytics";
import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js";
import getValidUser from "./utilities/getValidUser.js";
import { pnpTest } from "../pnp-test.js";
import { IUser } from "@pnp/graph/users";

describe("Analytics", function () {
let testUserName = "";
let user: IUser = null;
let site = null;
let driveId = null;
let listResultId = null;
Expand All @@ -28,19 +31,26 @@ describe("Analytics", function () {
};

// Ensure we have the data to test against
before(async function () {
before(pnpTest("6ffe9e49-a6d0-48a5-9adb-64cd85f7ef73", async function () {

if (!this.pnp.settings.enableWebTests || stringIsNullOrEmpty(this.pnp.settings.testUser)) {
this.skip();
}

const userInfo = await getValidUser.call(this);
user = this.pnp.graph.users.getById(userInfo.userPrincipalName);

// Create a sample list
try {
site = await getTestingGraphSPSite(this);
const props = await this.props({
title: "Test Item",
});

const listResult = await site.lists.add(sampleList);
listResultId = listResult.data.id;
const listItemProps: any = {
title: "Test Item",
title: props.title,
};
const listItem = await site.lists.getById(listResultId).items.add(listItemProps);
listItemId = listItem.data.id;
Expand All @@ -49,78 +59,84 @@ describe("Analytics", function () {
}
// Get a sample user
try {
testUserName = this.pnp.settings.testUser.substring(this.pnp.settings.testUser.lastIndexOf("|") + 1);
const drives = await this.pnp.graph.users.getById(testUserName).drives();
const drives = await user.drives();
if (drives.length > 0) {
driveId = drives[0].id;
}
} catch (err) {
console.log("Could not retrieve user's drives");
}
});

it("Get Drive Item Analytics - Last Seven Days", async function () {
if (listResultId === null || listItemId === null || driveId === null) {
this.skip();
}
}));

it("Get Drive Item Analytics - Last Seven Days", pnpTest("4915eeb3-97cf-447c-b7a6-d4ab445a41b9", async function () {
if (stringIsNullOrEmpty(driveId)) {
this.skip();
}
const testFileName = `TestFile_${getRandomString(4)}.txt`;
const props = await this.props({
testFileName: `TestFile_${getRandomString(4)}.txt`,
});
const fo = JSON.parse(JSON.stringify(fileOptions));
fo.filePathName = testFileName;
const children = await this.pnp.graph.users.getById(testUserName).drives.getById(driveId).root.upload(fo);
const analytics = await this.pnp.graph.users.getById(testUserName).drives.getById(driveId).getItemById(children.id).analytics();
fo.filePathName = props.testFileName;
const children = await user.drives.getById(driveId).root.upload(fo);
const analytics = await user.drives.getById(driveId).getItemById(children.id).analytics();
return expect(analytics).to.haveOwnProperty("@odata.context").eq("https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.itemActivityStat");
});
}));

// Analytics is not working on list items, returning item not found error.
it.skip("Get List Item Analytics - Last Seven Days", async function () {
it.skip("Get List Item Analytics - Last Seven Days", pnpTest("48aeeeca-0301-4af1-a47c-dd60e9ba459b", async function () {
if (stringIsNullOrEmpty(listItemId)) {
this.skip();
}
const analytics = await site.lists.getById(listResultId).items.getById(listItemId).analytics();
return expect(analytics).to.haveOwnProperty("@odata.context").eq("https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.itemActivityStat");
});
}));

it("Get Site Analytics - Last Seven Days", async function () {
it("Get Site Analytics - Last Seven Days", pnpTest("815b48d8-7604-4883-b085-59de28493d77", async function () {
if (stringIsNullOrEmpty(driveId)) {
this.skip();
}
const site = this.pnp.graph.sites.getById(this.pnp.settings.graph.id);
const analytics = await site.analytics();
return expect(analytics).to.haveOwnProperty("@odata.context").eq("https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.itemActivityStat");
});
}));

it("Get Drive Item Analytics - All Time", async function () {
it("Get Drive Item Analytics - All Time", pnpTest("721f17f5-836e-4c8d-a52a-a3b7068ac07d", async function () {
if (stringIsNullOrEmpty(driveId)) {
this.skip();
}
const testFileName = `TestFile_${getRandomString(4)}.txt`;

const props = await this.props({
testFileName: `TestFile_${getRandomString(4)}.txt`,
});
const fo = JSON.parse(JSON.stringify(fileOptions));
fo.filePathName = testFileName;
const children = await this.pnp.graph.users.getById(testUserName).drives.getById(driveId).root.upload(fo);
fo.filePathName = props.testFileName;
const children = await user.drives.getById(driveId).root.upload(fo);
const options: IAnalyticsOptions = { timeRange: "allTime" };
const analytics = await this.pnp.graph.users.getById(testUserName).drives.getById(driveId).getItemById(children.id).analytics(options);
const analytics = await user.drives.getById(driveId).getItemById(children.id).analytics(options);
return expect(analytics).to.haveOwnProperty("@odata.context").eq("https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.itemActivityStat");
});
}));

// Analytics is not working on list items, returning item not found error.
it.skip("Get List Item Analytics - All Time", async function () {
it.skip("Get List Item Analytics - All Time", pnpTest("37ffc5dc-ed88-4442-b7d7-aac068d25bbf", async function () {
if (stringIsNullOrEmpty(listItemId)) {
this.skip();
}
const options: IAnalyticsOptions = { timeRange: "allTime" };
const analytics = await site.lists.getById(listResultId).items.getById(listItemId).analytics(options);
return expect(analytics).to.haveOwnProperty("@odata.context").eq("https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.itemActivityStat");
});
}));

it("Get Site Analytics - All Time", async function () {
it("Get Site Analytics - All Time", pnpTest("94d06ed1-9414-4c39-be5a-0c0553b7a882", async function () {
if (stringIsNullOrEmpty(driveId)) {
this.skip();
}
const site = this.pnp.graph.sites.getById(this.pnp.settings.graph.id);
const options: IAnalyticsOptions = { timeRange: "allTime" };
const analytics = await site.analytics(options);
return expect(analytics).to.haveOwnProperty("@odata.context").eq("https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.itemActivityStat");
});
}));

// Remove the test contact we created
after(async function () {
Expand Down
Loading

0 comments on commit e5e7ae7

Please sign in to comment.