Skip to content

Commit d5bb8c4

Browse files
committed
Adding formdata to the node project, setting the esModuleInterop config as true for allowing import of npm modules, adding unit test for application/xhtml+xml content type post
1 parent 72adfd0 commit d5bb8c4

File tree

6 files changed

+73
-10
lines changed

6 files changed

+73
-10
lines changed

package-lock.json

Lines changed: 44 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
"@babel/plugin-transform-runtime": "^7.4.4",
2121
"@babel/preset-env": "^7.4.4",
2222
"@types/mocha": "^5.2.6",
23-
"@types/node": "^12.0.10",
23+
"@types/node": "^12.12.53",
2424
"chai": "^4.2.0",
25+
"form-data": "^3.0.0",
2526
"gulp": "^4.0.2",
2627
"husky": "^2.2.0",
2728
"isomorphic-fetch": "^2.2.1",

spec/development/workload/OneNote.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ describe("OneNote", function() {
8585
}
8686
});
8787

88+
it("Create a OneNote page with application/xhtml+xml page content", async () => {
89+
try {
90+
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>";
91+
const json = await client
92+
.api(`/me/onenote/sections/${section.id}/pages`)
93+
.header("content-type", "application/xhtml+xml")
94+
.post(body);
95+
const createdPageFromHTML = json as OnenotePage;
96+
console.log(json);
97+
assert.isDefined(createdPage.id);
98+
assert.isDefined(createdPage.contentUrl);
99+
assert.isUndefined(createdPage["random fake property that should be null"]);
100+
} catch (error) {
101+
throw error;
102+
}
103+
});
104+
88105
it("create a OneNote page with html page content and file attachment", async () => {
89106
try {
90107
const formData = new FormData();

src/GraphRequest.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* @module GraphRequest
1010
*/
1111

12+
import FormData from "form-data";
13+
1214
import { GraphError } from "./GraphError";
1315
import { GraphErrorHandler } from "./GraphErrorHandler";
1416
import { oDataQueryNames, serializeContent, urlJoin } from "./GraphRequestUtil";
@@ -22,7 +24,6 @@ import { MiddlewareControl } from "./middleware/MiddlewareControl";
2224
import { MiddlewareOptions } from "./middleware/options/IMiddlewareOptions";
2325
import { RequestMethod } from "./RequestMethod";
2426
import { ResponseType } from "./ResponseType";
25-
2627
/**
2728
* @interface
2829
* Signature to representing key value pairs
@@ -573,8 +574,9 @@ export class GraphRequest {
573574
method: RequestMethod.POST,
574575
body: serializeContent(content),
575576
};
576-
if (typeof FormData !== "undefined" && content instanceof FormData) {
577-
options.headers = {};
577+
const className: string = content === undefined || content === null ? undefined : content.constructor.name;
578+
if (typeof FormData !== "undefined" && className === "FormData") {
579+
options.headers = content.getHeaders();
578580
} else {
579581
this.buildHeaders();
580582
options.headers = this._headers;

tsconfig-cjs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"module": "commonjs",
55
"target": "es5",
66
"lib": ["dom", "esnext"],
7-
"outDir": "lib"
7+
"outDir": "lib",
8+
"esModuleInterop": true
89
},
910
"exclude": ["node_modules", "lib", "samples", "spec/development"],
1011
"include": ["./src/**/*.ts", "./spec/**/*.ts"]

tsconfig-es.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"extends": "./tsconfig-base.json",
33
"compilerOptions": {
4-
"module": "es6",
4+
"module": "CommonJS",
55
"target": "es6",
66
"lib": ["dom", "esnext"],
7-
"outDir": "lib/es"
7+
"outDir": "lib/es",
8+
"esModuleInterop": true
89
},
910
"exclude": ["node_modules", "lib", "samples", "spec/**"],
1011
"include": ["./src/**/*.ts"]

0 commit comments

Comments
 (0)