forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneNote.ts
More file actions
96 lines (83 loc) · 3.88 KB
/
Copy pathOneNote.ts
File metadata and controls
96 lines (83 loc) · 3.88 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
import { assert } from 'chai'
import { getClient, randomString } from "../test-helper"
import { Notebook, OnenoteSection, OnenotePage } from '@microsoft/microsoft-graph-types'
import * as fs from "fs";
import * as FormData from "form-data";
declare const describe, it;
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', function () {
return getClient().api("/me/onenote/notebooks").post(notebook).then((json) => {
const createdNotebook = json as Notebook;
assert.isDefined(createdNotebook.id);
assert.equal(notebook.displayName, createdNotebook.displayName);
assert.isUndefined(createdNotebook['invalidPropertyName']);
// if this passes, use this notebook in the following tests
notebook = createdNotebook;
return Promise.resolve();
});
});
it('Create a OneNote section in a Notebook', function () {
return getClient().api(`/me/onenote/notebooks/${notebook.id}/sections`).post(section).then((json) => {
const createdSection = json as OnenoteSection;
assert.isDefined(createdSection.id);
assert.equal(section.displayName, createdSection.displayName);
assert.isUndefined(createdSection['invalidPropertyName']);
// if this passes, use this notebook in the following tests
section = createdSection;
return Promise.resolve();
});
});
it('Create a OneNote page in a section with basic text content', function () {
return getClient()
.api(`/me/onenote/sections/${section.id}/pages`)
.header("Content-Type", "text/html")
.post(PageContent)
.then((json) => {
createdPage = json as OnenotePage;
assert.isDefined(createdPage.id);
assert.isDefined(createdPage.contentUrl);
assert.isUndefined(createdPage['invalidPropertyName']);
return Promise.resolve();
});
});
it("Create a OneNote page with html page content", () => {
let formData = new FormData();
formData.append('Presentation', fs.createReadStream('./spec/sample_files/onenotepage.html'));
return getClient()
.api(`/me/onenote/sections/${section.id}/pages`)
.post(formData)
.then((json) => {
let createdPageFromHTML = json as OnenotePage;
assert.isDefined(createdPage.id);
assert.isDefined(createdPage.contentUrl);
assert.equal("New Page", createdPageFromHTML.title);
assert.isUndefined(createdPage['invalidPropertyName']);
return Promise.resolve();
});
});
it("create a OneNote page with html page content and file attachment", () => {
let formData = new FormData();
formData.append('Presentation', fs.createReadStream('./spec/sample_files/onenotepage_fileattachment.html'));
formData.append("fileBlock1", fs.createReadStream("./sample.png"));
return getClient()
.api(`/me/onenote/sections/${section.id}/pages`)
.post(formData)
.then((json) => {
let 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['invalidPropertyName']);
return Promise.resolve();
});
});
});