Skip to content

Commit 099fa02

Browse files
committed
Adding unit test for serializecontent testing if content is null, changed content type setting for put and patch
1 parent d5bb8c4 commit 099fa02

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

spec/core/GraphRequestUtil.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,10 @@ describe("GraphRequestUtil.ts", () => {
7171
const val = undefined;
7272
assert.equal(serializeContent(val), undefined);
7373
});
74+
75+
it("Should return 'null' for the case of null content value", () => {
76+
const val = null;
77+
assert.equal(serializeContent(val), "null");
78+
});
7479
});
7580
});

spec/development/workload/OneNote.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ describe("OneNote", function() {
9393
.header("content-type", "application/xhtml+xml")
9494
.post(body);
9595
const createdPageFromHTML = json as OnenotePage;
96-
console.log(json);
9796
assert.isDefined(createdPage.id);
9897
assert.isDefined(createdPage.contentUrl);
9998
assert.isUndefined(createdPage["random fake property that should be null"]);

src/GraphRequest.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export class GraphRequest {
309309
* @param none
310310
* @returns nothing
311311
*/
312-
private buildHeaders(): void {
312+
private setHeaderContentType(): void {
313313
if (this._headers === undefined || this._headers === null) {
314314
this.header("Content-Type", "application/json");
315315
}
@@ -320,6 +320,7 @@ export class GraphRequest {
320320
isContentTypePresent = true;
321321
}
322322
}
323+
// Default the content-type to application/json in case the content-type is not present in the header
323324
if (!isContentTypePresent) {
324325
this.header("Content-Type", "application/json");
325326
}
@@ -576,9 +577,10 @@ export class GraphRequest {
576577
};
577578
const className: string = content === undefined || content === null ? undefined : content.constructor.name;
578579
if (typeof FormData !== "undefined" && className === "FormData") {
579-
options.headers = content.getHeaders();
580+
// Content-Type headers should not be specified in case the of FormData type content
581+
options.headers = {};
580582
} else {
581-
this.buildHeaders();
583+
this.setHeaderContentType();
582584
options.headers = this._headers;
583585
}
584586
try {
@@ -615,12 +617,10 @@ export class GraphRequest {
615617
*/
616618
public async put(content: any, callback?: GraphRequestCallback): Promise<any> {
617619
const url = this.buildFullUrl();
620+
this.setHeaderContentType();
618621
const options: FetchOptions = {
619622
method: RequestMethod.PUT,
620623
body: serializeContent(content),
621-
headers: {
622-
"Content-Type": "application/json",
623-
},
624624
};
625625
try {
626626
const response = await this.send(url, options, callback);
@@ -640,12 +640,10 @@ export class GraphRequest {
640640
*/
641641
public async patch(content: any, callback?: GraphRequestCallback): Promise<any> {
642642
const url = this.buildFullUrl();
643+
this.setHeaderContentType();
643644
const options: FetchOptions = {
644645
method: RequestMethod.PATCH,
645646
body: serializeContent(content),
646-
headers: {
647-
"Content-Type": "application/json",
648-
},
649647
};
650648
try {
651649
const response = await this.send(url, options, callback);

0 commit comments

Comments
 (0)