-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathsaveToOneNote_tests.ts
More file actions
685 lines (567 loc) · 23.8 KB
/
saveToOneNote_tests.ts
File metadata and controls
685 lines (567 loc) · 23.8 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
import * as sinon from "sinon";
import {MockPdfDocument} from "../contentCapture/mockPdfDocument";
import {Constants} from "../../scripts/constants";
import {Clipper} from "../../scripts/clipperUI/frontEndGlobals";
import {StubSessionLogger} from "../../scripts/logging/stubSessionLogger";
import {SaveToOneNote} from "../../scripts/saveToOneNote/saveToOneNote";
import {OneNoteSaveablePage} from "../../scripts/saveToOneNote/oneNoteSaveablePage";
import {OneNoteSaveablePdf} from "../../scripts/saveToOneNote/oneNoteSaveablePdf";
import {OneNoteSaveablePdfSynchronousBatched} from "../../scripts/saveToOneNote/oneNoteSaveablePdfSynchronousBatched";
import {ClipperStorageKeys} from "../../scripts/storage/clipperStorageKeys";
import {AsyncUtils} from "../asyncUtils";
import {TestModule} from "../testModule";
export class SaveToOneNoteTests extends TestModule {
private server: sinon.SinonFakeServer;
private saveToOneNote: SaveToOneNote;
protected module() {
return "saveToOneNote";
}
protected beforeEach() {
AsyncUtils.mockSetTimeout();
this.server = sinon.fakeServer.create();
this.server.respondImmediately = true;
this.saveToOneNote = new SaveToOneNote("userToken");
}
protected afterEach() {
AsyncUtils.restoreSetTimeout();
this.server.restore();
}
protected tests() {
test("When saving a 'just a page', save() should resolve with the parsed response and request in a responsePackage if the API call succeeds", (assert: QUnitAssert) => {
let done = assert.async();
let saveLocation = "sectionId";
let responseJson = {
key: "value"
};
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/sections/" + saveLocation + "/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePage(), saveLocation: saveLocation }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, responseJson, "The parsedResponse field should be the response in json form");
ok(responsePackage.request, "The request field should be defined");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a 'just a page', save() should resolve with the parsed response and request in a responsePackage if the API call succeeds and no saveLocation is specified", (assert: QUnitAssert) => {
let done = assert.async();
let responseJson = {
key: "value"
};
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePage() }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, responseJson, "The parsedResponse field should be the response in json form");
ok(responsePackage.request, "The request field should be defined");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a 'just a page', but the this.server returns an unexpected response code, reject should be called with the error object", (assert: QUnitAssert) => {
let done = assert.async();
let responseJson = {
key: "value"
};
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[404, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePage() }).then((responsePackage) => {
ok(false, "resolve should not be called");
}, (error) => {
deepEqual(error,
{ error: "Unexpected response status", statusCode: 404, responseHeaders: { "Content-Type": "application/json" }, response: JSON.stringify(responseJson), timeout: 30000 },
"The error object should be returned in the reject");
}).then(() => {
done();
});
});
// From this point, we now test cases where we hit multiple endpoints. For this to work, we need to declare the fakeServer
// responses before the this.saveToOneNote call otherwise the fakeServer will respond with 404
test("When saving a pdf, save() should resolve with the parsed response and request in a responsePackage assuming the patch permissions call succeeds", (assert: QUnitAssert) => {
let done = assert.async();
let saveLocation = "mySection";
let pageId = "abc";
let createPageJson = {
id: pageId
};
// Request patch permissions
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/sections/" + saveLocation + "/pages?top=1",
[200, { "Content-Type": "application/json" },
JSON.stringify({ getPages: "getPages" })
]);
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/sections/" + saveLocation + "/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJson)
]);
// Check that page exists before patching
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ getPage: "getPage" })
]);
// Patch to the page
this.server.respondWith(
"PATCH", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ updatePage: "updatePage" })
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]), saveLocation: saveLocation }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJson, "The parsedResponse field should be the create page response in json form");
ok(responsePackage.request, "The request field should be defined");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a pdf to the default location, save() should resolve with the parsed response and request in a responsePackage assuming the patch permissions call succeeds", (assert: QUnitAssert) => {
let done = assert.async();
let pageId = "abc";
let createPageJson = {
id: pageId
};
// Request patch permissions
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages?top=1",
[200, { "Content-Type": "application/json" },
JSON.stringify({ getPages: "getPages" })
]);
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJson)
]);
// Check that page exists before patching
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ getPage: "getPage" })
]);
// Patch to the page
this.server.respondWith(
"PATCH", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ updatePage: "updatePage" })
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]) }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJson, "The parsedResponse field should be the create page response in json form");
ok(responsePackage.request, "The request field should be defined");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a pdf, save() should resolve with the parsed response and request in a responsePackage assuming the patch permission validity has been cached in localStorage", (assert: QUnitAssert) => {
let done = assert.async();
Clipper.storeValue(ClipperStorageKeys.hasPatchPermissions, "true");
let pageId = "abc";
let createPageJson = {
id: pageId
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJson)
]);
// Check that page exists before patching
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ getPage: "getPage" })
]);
// Update page with pdf pages
this.server.respondWith(
"PATCH", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ updatePage: "updatePage" })
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]) }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJson, "The parsedResponse field should be the create page response in json form");
ok(responsePackage.request, "The request field should be defined");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a single page pdf in BATCH mode, save() should resolve with the first createPage response and request in a responsePackage, assuming all createPages succeeded", (assert: QUnitAssert) => {
// Create initialPage
let done = assert.async();
let saveLocation = "mySection";
let pageId = "abc";
let createPageJson = {
id: pageId
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/sections/" + saveLocation + "/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdfSynchronousBatch([]), saveLocation: saveLocation }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJson, "The parsedResponse field should be the create page response in json form");
ok(responsePackage.request, "The request field should be defined");
strictEqual(this.server.requests.length, 1, "A 1-page PDF that is distributing pages should make exactly 1 call to the API");
}, (error) => {
ok(false, "reject should not be called: " + error);
}).then(() => {
done();
});
});
test("When saving a single page pdf in BATCH mode, save() should resolve with the first createPage response and request in a responsePackage, assuming all createPages succeeded and no saveLocation is specified", (assert: QUnitAssert) => {
let done = assert.async();
let pageId = "abc";
let createPageJsonOne = {
id: pageId
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJsonOne)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdfSynchronousBatch([]) }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJsonOne, "The parsedResponse field should be the create page response in json form of the first createPage request");
ok(responsePackage.request, "The request field should be defined");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a multi-page pdf in BATCH mode, save() should resolve with the first createPage response and request in a responsePackage, assuming all createPages succeeded", (assert: QUnitAssert) => {
let done = assert.async();
let saveLocation = "mySection";
let pageId = "abc";
let createPageJsonOne = {
id: pageId
};
let pageIdTwo = "def";
let createPageJsonTwo = {
id: pageIdTwo
};
let responses = [createPageJsonOne, createPageJsonTwo];
const responseClass = new class {
private responses = responses;
private count = 0;
respond = (request) => {
const response = this.responses[this.count];
this.count++;
request.respond(201, { "Content-Type": "application/json" }, JSON.stringify(response));
}
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/sections/" + saveLocation + "/pages", responseClass.respond
);
this.saveToOneNote.save({ page: this.getMockSaveablePdfSynchronousBatch([1]), saveLocation: saveLocation }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJsonOne, "The parsedResponse field should be the create page response in json form of the first createPage request");
ok(responsePackage.request, "The request field should be defined");
strictEqual(this.server.requests.length, 2, "A 2-page PDF that is distributing pages should make exactly 2 calls to the API");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a multi-page pdf in BATCH mode, save() should resolve with the first createPage response and request in a responsePackage, assuming all createPages succeeded and no saveLocation is specified", (assert: QUnitAssert) => {
let done = assert.async();
let pageId = "abc";
let createPageJsonOne = {
id: pageId
};
let pageIdTwo = "def";
let createPageJsonTwo = {
id: pageIdTwo
};
let responses = [createPageJsonOne, createPageJsonTwo];
const responseClass = new class {
private responses = responses;
private count = 0;
respond = (request) => {
const response = this.responses[this.count];
this.count++;
request.respond(201, { "Content-Type": "application/json" }, JSON.stringify(response));
}
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages", responseClass.respond
);
this.saveToOneNote.save({ page: this.getMockSaveablePdfSynchronousBatch([1]) }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJsonOne, "The parsedResponse field should be the create page response in json form of the first createPage request");
ok(responsePackage.request, "The request field should be defined");
strictEqual(this.server.requests.length, 2, "A 2-page PDF that is distributing pages should make exactly 2 calls to the API");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a pdf that is distribued over many pages, if the first page creation fails, reject should be called with the error object", (assert: QUnitAssert) => {
let done = assert.async();
let responseJson = {
key: "value"
};
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[404, { "Content-Type": "application/json" }, JSON.stringify(responseJson)]
);
this.saveToOneNote.save({ page: this.getMockSaveablePdfSynchronousBatch([1]) }).then((responsePackage) => {
ok(false, "resolve should not be called");
}, (error) => {
deepEqual(error,
{ error: "Unexpected response status", statusCode: 404, responseHeaders: { "Content-Type": "application/json" }, response: JSON.stringify(responseJson), timeout: 30000 },
"The error object should be returned in the reject");
}).then(() => {
done();
});
});
test("When saving a pdf that is distributed over many pages, if any of the createPage calls fail, the call should still resolve", (assert: QUnitAssert) => {
let done = assert.async();
let pageId1 = "abc";
let createPageJson1 = {
id: pageId1
};
let pageId2 = "def";
let createPageJson2 = {
id: pageId2
};
let errorResponse = {
key: "value"
};
let pageId3 = "ghi";
let createPageJson3 = {
id: pageId3
};
let headers = { "Content-Type": "application/json" };
let responses = [
{
statusCode: 201,
headers: headers,
body: JSON.stringify(createPageJson1)
},
{
statusCode: 201,
headers: headers,
body: JSON.stringify(createPageJson2)
},
{
statusCode: 404,
headers: headers,
body: JSON.stringify(errorResponse)
},
{
statusCode: 201,
headers: headers,
body: JSON.stringify(createPageJson3)
}
];
const responseClass = new class {
private responses = responses;
private count = 0;
respond = (request) => {
const response = this.responses[this.count];
this.count++;
request.respond(response.statusCode, response.headers, response.body);
}
};
// Initial create page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages", responseClass.respond
);
this.saveToOneNote.save({ page: this.getMockSaveablePdfSynchronousBatch([1]) }).then((responsePackage) => {
deepEqual(responsePackage.parsedResponse, createPageJson1, "The parsedResponse field should be the create page response in json form of the first createPage request");
ok(responsePackage.request, "The request field should be defined");
}, (error) => {
ok(false, "reject should not be called");
}).then(() => {
done();
});
});
test("When saving a pdf and a PATCH permission check is needed, but that check returns an unexpected response code, reject should be called with the error object", (assert: QUnitAssert) => {
let done = assert.async();
let responseJson = {
getPages: "getPages"
};
// Request patch permissions
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages?top=1",
[404, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]) }).then((responsePackage) => {
ok(false, "resolve should not be called");
}, (error) => {
deepEqual(error,
{ error: "Unexpected response status", statusCode: 404, responseHeaders: { "Content-Type": "application/json" }, response: JSON.stringify(responseJson), timeout: 30000 },
"The error object should be returned in the reject");
}).then(() => {
done();
});
});
test("When saving a pdf, if the page creation fails, reject should be called with the error object", (assert: QUnitAssert) => {
let done = assert.async();
Clipper.storeValue(ClipperStorageKeys.hasPatchPermissions, "true");
let responseJson = {
getPages: "getPages"
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[404, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]) }).then((responsePackage) => {
ok(false, "resolve should not be called");
}, (error) => {
deepEqual(error,
{ error: "Unexpected response status", statusCode: 404, responseHeaders: { "Content-Type": "application/json" }, response: JSON.stringify(responseJson), timeout: 30000 },
"The error object should be returned in the reject");
}).then(() => {
done();
});
});
test("When saving a pdf, if the check for page existence fails, reject should be called with the error object", (assert: QUnitAssert) => {
let done = assert.async();
Clipper.storeValue(ClipperStorageKeys.hasPatchPermissions, "true");
let pageId = "abc";
let createPageJson = {
id: pageId
};
let responseJson = {
getPages: "getPages"
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJson)
]);
// Check that page exists before patching
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[404, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]) }).then((responsePackage) => {
ok(false, "resolve should not be called");
}, (error) => {
deepEqual(error,
{ error: "Unexpected response status", statusCode: 404, responseHeaders: { "Content-Type": "application/json" }, response: JSON.stringify(responseJson), timeout: 30000 },
"The error object should be returned in the reject");
}).then(() => {
done();
});
});
test("When saving a pdf, if the PATCH call fails, reject should be called with the error object", (assert: QUnitAssert) => {
let done = assert.async();
Clipper.storeValue(ClipperStorageKeys.hasPatchPermissions, "true");
let pageId = "abc";
let createPageJson = {
id: pageId
};
let responseJson = {
getPages: "getPages"
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJson)
]);
// Check that page exists before patching
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ getPage: "getPage" })
]);
// Update page with pdf pages
this.server.respondWith(
"PATCH", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[404, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]) }).then((responsePackage) => {
ok(false, "resolve should not be called");
}, (error) => {
deepEqual(error,
{ error: "Unexpected response status", statusCode: 404, responseHeaders: { "Content-Type": "application/json" }, response: JSON.stringify(responseJson), timeout: 30000 },
"The error object should be returned in the reject");
}).then(() => {
done();
});
});
test("When saving a pdf and a save location is specified, if the PATCH call fails, reject should be called with the error object", (assert: QUnitAssert) => {
let done = assert.async();
Clipper.storeValue(ClipperStorageKeys.hasPatchPermissions, "true");
let saveLocation = "sectionId";
let pageId = "abc";
let createPageJson = {
id: pageId
};
let responseJson = {
getPages: "getPages"
};
// Create initial page
this.server.respondWith(
"POST", "https://www.onenote.com/api/v1.0/me/notes/sections/" + saveLocation + "/pages",
[200, { "Content-Type": "application/json" },
JSON.stringify(createPageJson)
]);
// Check that page exists before patching
this.server.respondWith(
"GET", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[200, { "Content-Type": "application/json" },
JSON.stringify({ getPage: "getPage" })
]);
// Update page with pdf pages
this.server.respondWith(
"PATCH", "https://www.onenote.com/api/v1.0/me/notes/pages/" + pageId + "/content",
[404, { "Content-Type": "application/json" },
JSON.stringify(responseJson)
]);
this.saveToOneNote.save({ page: this.getMockSaveablePdf([0, 1]), saveLocation: saveLocation }).then((responsePackage) => {
ok(false, "resolve should not be called");
}, (error) => {
deepEqual(error,
{ error: "Unexpected response status", statusCode: 404, responseHeaders: { "Content-Type": "application/json" }, response: JSON.stringify(responseJson), timeout: 30000 },
"The error object should be returned in the reject");
}).then(() => {
done();
});
});
}
private getMockSaveablePage(): OneNoteSaveablePage {
let page = new OneNoteApi.OneNotePage();
return new OneNoteSaveablePage(page);
}
private getMockSaveablePdf(pageIndexes?: number[]): OneNoteSaveablePdf {
let page = new OneNoteApi.OneNotePage();
let mockPdf = new MockPdfDocument();
return new OneNoteSaveablePdf(page, mockPdf, pageIndexes);
}
private getMockSaveablePdfSynchronousBatch(pageIndexes: number[]): OneNoteSaveablePdfSynchronousBatched {
let page = new OneNoteApi.OneNotePage();
let mockPdf = new MockPdfDocument();
return new OneNoteSaveablePdfSynchronousBatched(page, mockPdf, pageIndexes, "en-US", "sample.pdf");
}
}
(new SaveToOneNoteTests()).runTests();