-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathOneNote.ts
More file actions
119 lines (107 loc) · 4.41 KB
/
OneNote.ts
File metadata and controls
119 lines (107 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { assert } from "chai";
import FormData from "form-data";
import fs from "fs";
import { Notebook, OnenotePage, OnenoteSection } from "microsoft-graph";
import { getClient, randomString } from "../test-helper";
const client = getClient();
describe("OneNote", function() {
this.timeout(20 * 1000);
let notebook: Notebook = {
displayName: "Sample notebook - " + randomString(),
};
let section: OnenoteSection = {
displayName: "Sample section - " + randomString(),
};
let createdPage: OnenotePage;
const PageContent = "Sample page content - " + randomString();
it("Create a OneNote notebook", async () => {
try {
const json = await client.api("/me/onenote/notebooks").post(notebook);
const createdNotebook = json as Notebook;
assert.isDefined(createdNotebook.id);
assert.equal(notebook.displayName, createdNotebook.displayName);
assert.isUndefined(createdNotebook["random fake property that should be null"]);
// if this passes, use this notebook in the following tests
notebook = createdNotebook;
} catch (error) {
throw error;
}
});
it("Create a OneNote section in a Notebook", async () => {
try {
const json = await client.api(`/me/onenote/notebooks/${notebook.id}/sections`).post(section);
const createdSection = json as OnenoteSection;
assert.isDefined(createdSection.id);
assert.equal(section.displayName, createdSection.displayName);
assert.isUndefined(createdSection["random fake property that should be null"]);
// if this passes, use this notebook in the following tests
section = createdSection;
} catch (error) {
throw error;
}
});
it("Create a OneNote page in a section with basic text content", async () => {
try {
const json = await client
.api(`/me/onenote/sections/${section.id}/pages`)
.header("Content-Type", "text/html")
.post(PageContent);
createdPage = json as OnenotePage;
assert.isDefined(createdPage.id);
assert.isDefined(createdPage.contentUrl);
assert.isUndefined(createdPage["random fake property that should be null"]);
} catch (error) {
throw error;
}
});
it("Create a OneNote page with html page content", async () => {
try {
const formData = new FormData();
formData.append("Presentation", fs.createReadStream("./spec/sample_files/onenotepage.html"));
const json = await client.api(`/me/onenote/sections/${section.id}/pages`).post(formData);
const createdPageFromHTML = json as OnenotePage;
assert.isDefined(createdPage.id);
assert.isDefined(createdPage.contentUrl);
assert.equal("New Page", createdPageFromHTML.title);
assert.isUndefined(createdPage["random fake property that should be null"]);
} catch (error) {
throw error;
}
});
it("Create a OneNote page with application/xhtml+xml page content", async () => {
try {
const body = "<!DOCTYPE html><html><head><title>A page with a block of HTML</title></head><body><p>This page contains some <i>formatted</i> <b>text</b>.</p></body></html>";
const json = await client
.api(`/me/onenote/sections/${section.id}/pages`)
.header("content-type", "application/xhtml+xml")
.post(body);
const createdPageFromHTML = json as OnenotePage;
assert.isDefined(createdPage.id);
assert.isDefined(createdPage.contentUrl);
assert.isUndefined(createdPage["random fake property that should be null"]);
} catch (error) {
throw error;
}
});
it("create a OneNote page with html page content and file attachment", async () => {
try {
const formData = new FormData();
formData.append("Presentation", fs.createReadStream("./spec/sample_files/onenotepage_fileattachment.html"));
formData.append("fileBlock1", fs.createReadStream("./sample.png"));
const json = await client.api(`/me/onenote/sections/${section.id}/pages`).post(formData);
const createdPageFromHTML = json as OnenotePage;
assert.isDefined(createdPage.id);
assert.isDefined(createdPage.contentUrl);
assert.equal("A page with rendered file attachment", createdPageFromHTML.title);
assert.isUndefined(createdPage["random fake property that should be null"]);
} catch (error) {
throw error;
}
});
});