Skip to content

Commit

Permalink
Bug fixes and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Julie Turner committed Feb 28, 2024
1 parent 54bc187 commit deb67b1
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 106 deletions.
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
59 changes: 32 additions & 27 deletions test/graph/list-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import { IListItem } from "@pnp/graph/list-item/types.js";
describe("List-Items", function () {
let site: ISite;
let list: IList;
let item: IListItem;
let itemUpdate: IListItem;
let itemDelete: IListItem;
let itemDeleteId: string;

const sampleList: List = {
displayName: "PnPGraphTestList",
list: { "template": "ItemTestList-Graph" },
list: { template: "genericList" },
};

before(async function () {
before(pnpTest("b4387653-1d11-49f3-b722-8a305f8f6495", async function () {

if (!this.pnp.settings.enableWebTests) {
this.skip();
Expand All @@ -28,20 +30,23 @@ describe("List-Items", function () {
site = await getTestingGraphSPSite(this);

const props = await this.props({
displayName: getRandomString(5) + "Add",
displayName: `Add${getRandomString(5)}`,
});

const listTemplate = JSON.parse(JSON.stringify(sampleList));
listTemplate.displayName += props.displayName;
const list = (await site.lists.add(listTemplate)).list;
list = (await site.lists.add(listTemplate)).list;

// add test items. Document set can be added later
if(list){
await list.items.add({Title: `Item ${getRandomString(4)}`} as any);
await list.items.add({Title: `Item ${getRandomString(4)}`} as any);
const newItem = await list.items.add({Title: `Item ${getRandomString(4)}`} as any);
itemUpdate = list.items.getById(newItem.id);
const newItem2 = await list.items.add({Title: `Item ${getRandomString(4)}`} as any);
itemDeleteId = newItem2.id;
itemDelete = list.items.getById(newItem2.id);
}

});
}));

it("items", pnpTest("3e0e16a0-5683-4c3a-aa3d-f35bb6912de1", async function () {
const items = await list.items();
Expand All @@ -54,57 +59,57 @@ describe("List-Items", function () {
}));

it("add", pnpTest("587e280b-0342-4515-a166-1b05cee9f242", async function () {
// fieldvalueset. ugh. Casting as any.
const itemAdded = await list.items.add({fields:
{
title: getRandomString(5) + "Add",
Title: `Add ${getRandomString(5)}`,
},
} as any);

return expect((itemAdded.id)).is.not.null;
return expect((itemAdded.id)).length.is.gt(0);
}));

it("update", pnpTest("5766613a-51b8-4f88-ba0f-2436d160b86b", async function () {
// fieldvalueset. ugh. Casting as any.
const itemUpdated = await item.update({fields:
const newTitle = `Updated ${getRandomString(5)}`;
const itemUpdated = await itemUpdate.update({fields:
{
title: getRandomString(5) + "Update",
Title: newTitle,
},
} as any);


return expect(itemUpdated).is.not.null;
return expect(itemUpdated.fields.Title).is.eq(newTitle);
}));

it("delete", pnpTest("e55bf53f-1316-4e47-97c1-b0c0cdd860ef", async function () {
const item = await list.items.add({fields:
{
title: getRandomString(5) + "Add",
},
} as any);
const r = await list.items.filter(`Id eq '${item.id}'`)();
return expect(r.length).to.eq(0);
await itemDelete.delete();
let passed = false;
try{
const r = await list.items.getById(itemDeleteId)();
}catch(err){
passed = true;
}
return expect(passed).to.be.true;
}));

it.skip("documentSetVersions", pnpTest("c2889ca3-0230-4c6e-879d-71cc9cd08e83", async function () {
const versions = await item.documentSetVersions();
const versions = await itemUpdate.documentSetVersions();
return expect(versions).to.be.an("array") && expect(versions[0]).to.haveOwnProperty("id");
}));

it.skip("documentSetVersions - getById()", pnpTest("35226d93-204b-4877-9041-26e04e437914", async function () {
const versions = await item.documentSetVersions();
const versions = await itemUpdate.documentSetVersions();

const version = await item.documentSetVersions.getById(versions[0].id);
const version = await itemUpdate.documentSetVersions.getById(versions[0].id);
return expect(version).to.not.be.null && expect(version).to.haveOwnProperty("id");
}));

it.skip("documentSetVersions - add()", pnpTest("a192e096-fe84-4c2c-adc5-b1b9021c0031", async function () {
const documentSetVersion = await item.documentSetVersions.add({comment:"Test Comment"});
const documentSetVersion = await itemUpdate.documentSetVersions.add({comment:"Test Comment"});
return expect(documentSetVersion).to.not.be.null && expect(documentSetVersion).to.haveOwnProperty("id");
}));

it.skip("documentSetVersions - restore()", pnpTest("8814b247-4087-4c87-9a8f-af997f7d8745", async function () {
const restore = await item.documentSetVersions[0].restore();
const restore = await itemUpdate.documentSetVersions[0].restore();
return expect(restore).to.be.fulfilled;
}));

Expand Down
Loading

0 comments on commit deb67b1

Please sign in to comment.