1+ import { assert } from 'chai'
2+
3+ import { getClient , randomString } from "./test-helper"
4+ import { Notebook , Section , Page } from '@microsoft/microsoft-graph-types-beta'
5+
6+ declare const describe , it ;
7+
8+ describe ( 'OneNote' , function ( ) {
9+ this . timeout ( 20 * 1000 ) ;
10+ let notebook :Notebook = {
11+ name : "Sample notebook - " + randomString ( )
12+ } ;
13+
14+ let section :Section = {
15+ name : "Sample section - " + randomString ( )
16+ }
17+
18+ let createdPage :Page ;
19+ const PageContent = "Sample page content - " + randomString ( ) ;
20+
21+ const HTMLPageTitle = `Another page ${ randomString ( ) } !`
22+ const HTMLPageContent = `
23+ <!DOCTYPE html>
24+ <html>
25+ <head>
26+ <title>${ HTMLPageTitle } </title>
27+ </head>
28+ <body>
29+ <p>Created a OneNote page from <b>HTML</b></p>
30+ </body>
31+ </html>
32+ `
33+
34+ it ( 'Create a OneNote notebook' , function ( ) {
35+ return getClient ( ) . api ( "https://graph.microsoft.com/beta/me/notes/notebooks" ) . post ( notebook ) . then ( ( json ) => {
36+ const createdNotebook = json as Notebook ;
37+ assert . isDefined ( createdNotebook . id ) ;
38+ assert . equal ( notebook . name , createdNotebook . name ) ;
39+ assert . isUndefined ( createdNotebook [ 'invalidPropertyName' ] ) ;
40+
41+ // if this passes, use this notebook in the following tests
42+ notebook = createdNotebook ;
43+ return Promise . resolve ( ) ;
44+ } ) ;
45+ } ) ;
46+
47+ it ( 'Create a OneNote section in a Notebook' , function ( ) {
48+ return getClient ( ) . api ( `https://graph.microsoft.com/beta/me/notes/notebooks/${ notebook . id } /sections` ) . post ( section ) . then ( ( json ) => {
49+ const createdSection = json as Section ;
50+ assert . isDefined ( createdSection . id ) ;
51+ assert . equal ( section . name , createdSection . name ) ;
52+ assert . isUndefined ( createdSection [ 'invalidPropertyName' ] ) ;
53+
54+ // if this passes, use this notebook in the following tests
55+ section = createdSection ;
56+ return Promise . resolve ( ) ;
57+
58+ } ) ;
59+ } ) ;
60+
61+
62+ it ( 'Create a OneNote page in a section with basic text content' , function ( ) {
63+ return getClient ( )
64+ . api ( `https://graph.microsoft.com/beta/me/notes/sections/${ section . id } /pages` )
65+ . header ( "Content-Type" , "text/html" )
66+ . post ( PageContent )
67+ . then ( ( json ) => {
68+ createdPage = json as Page ;
69+ assert . isDefined ( createdPage . id ) ;
70+ assert . isDefined ( createdPage . contentUrl ) ;
71+ assert . isUndefined ( createdPage [ 'invalidPropertyName' ] ) ;
72+
73+ return Promise . resolve ( ) ;
74+ } ) ;
75+ } ) ;
76+
77+ it ( 'Create a OneNote page from application/xhtml+xml content and boundary headers' , function ( ) {
78+ return getClient ( )
79+ . api ( `https://graph.microsoft.com/beta/me/notes/sections/${ section . id } /pages` )
80+ . header ( "Content-Type" , "application/xhtml+xml" )
81+ . header ( "boundary" , `MyPartBoundary${ randomString ( ) } ` )
82+ . post ( HTMLPageContent )
83+ . then ( ( json ) => {
84+ let createdPageFromHTML = json as Page ;
85+ assert . isDefined ( createdPage . id ) ;
86+ assert . isDefined ( createdPage . contentUrl ) ;
87+ assert . equal ( HTMLPageTitle , createdPageFromHTML . title )
88+ assert . isUndefined ( createdPage [ 'invalidPropertyName' ] ) ;
89+ return Promise . resolve ( ) ;
90+ } ) ;
91+ } )
92+ } ) ;
0 commit comments