Skip to content

Commit c23c2a0

Browse files
committed
Tests for groups, onenote, open extensions and people
1 parent 8dbb585 commit c23c2a0

File tree

13 files changed

+349
-6
lines changed

13 files changed

+349
-6
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ samples/typescript/sample.d.ts
1515
samples/typescript/graph-typings.d.ts
1616
samples/typescript/sample.js.map
1717
src/index.d.ts
18-
test/secrets.json
18+
19+
spec/types/secrets*
20+
spec/types/*.js
21+
spec/types/*.d.ts
22+
spec/types/*.js.map

lib/spec/core/urlGeneration.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"scripts": {
1919
"build": "tsc && node node-browserify.js > lib/graph-js-sdk-web.js",
2020
"test": "mocha lib/spec/core",
21-
"test:types": "mocha lib/spec/types"
21+
"test:types": "tsc --p spec/types && mocha spec/types"
2222
},
2323
"dependencies": {
2424
"superagent": "^3.5.2",

spec/core/urlGeneration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from 'assert';
22

3-
import {Client as GraphClient} from "../../src/index"
3+
import { Client as GraphClient } from "../../src/index"
44

55
const client = GraphClient.init();
66

spec/types/OneNote.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
});

spec/types/groups.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {assert} from 'chai'
2+
3+
import { getClient, randomString } from "./test-helper"
4+
import { Group } from '@microsoft/microsoft-graph-types'
5+
6+
declare const describe, it;
7+
8+
describe('Groups', function() {
9+
this.timeout(10*1000);
10+
it('Fetch a list of groups and access properties on a collection item', function() {
11+
return getClient().api("https://graph.microsoft.com/v1.0/groups/").get().then((json) => {
12+
const group = json.value[0] as Group;
13+
assert.isDefined(group.displayName);
14+
assert.isDefined(group.mail);
15+
assert.isDefined(group.id);
16+
17+
assert.isUndefined(group['invalidPropertyName']);
18+
return Promise.resolve();
19+
});
20+
});
21+
22+
it('Create a group and validate properties were set', function() {
23+
const group:Group = {
24+
displayName: "Sample test group",
25+
description: randomString(),
26+
groupTypes: [
27+
"Unified"
28+
],
29+
mailEnabled: true,
30+
mailNickname: "Group911e5",
31+
securityEnabled: true
32+
};
33+
34+
return getClient().api("https://graph.microsoft.com/v1.0/groups/").post(group).then((groupResponse) => {
35+
let createdGroup = groupResponse as Group;
36+
assert.equal(createdGroup.displayName, group.displayName);
37+
assert.equal(createdGroup.description, group.description);
38+
assert.equal(createdGroup.mailEnabled, group.mailEnabled);
39+
assert.isString(createdGroup.id);
40+
return Promise.resolve();
41+
});
42+
});
43+
});

spec/types/open-extensions.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { assert } from 'chai'
2+
3+
import { getClient, randomString } from "./test-helper"
4+
import { OpenTypeExtension, User } from '@microsoft/microsoft-graph-types-beta'
5+
6+
declare const describe, it;
7+
8+
interface ColorOpenExtension extends OpenTypeExtension {
9+
color: string
10+
}
11+
12+
let extension:ColorOpenExtension = {
13+
extensionName: `com.javascript.extension-${randomString()}`,
14+
color: randomString()
15+
}
16+
17+
describe('Open Extensions', function() {
18+
this.timeout(10*1000);
19+
it('Use open extensions to add a field to users', function() {
20+
return getClient().api("https://graph.microsoft.com/beta/me/extensions").post(extension).then((json) => {
21+
const createdExtension = json as ColorOpenExtension;
22+
23+
assert.isDefined(createdExtension.id);
24+
assert.equal(createdExtension.color, extension.color);
25+
assert.equal(createdExtension.extensionName, extension.extensionName);
26+
27+
assert.isUndefined(createdExtension['invalidPropertyName']);
28+
29+
// save this createdExtension for later tests (id)
30+
extension = createdExtension;
31+
return Promise.resolve();
32+
});
33+
});
34+
35+
// it('Queries open extension values on a user', function() {
36+
// return getClient().api("https://graph.microsoft.com/beta/me?$select=id&$expand=extensions").get().then((json) => {
37+
// let user = json as User;
38+
// for (let userExtension of user.extensions) {
39+
// if (userExtension.id == extension.id) {
40+
// return Promise.resolve();
41+
// }
42+
// }
43+
// return Promise.reject("Created extension not found when iterating user extensions");
44+
// });
45+
// });
46+
47+
it('Deletes the created open extension', function() {
48+
return getClient().api(`https://graph.microsoft.com/beta/me/extensions/${extension.id}`).delete()
49+
});
50+
});

spec/types/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"devDependencies": {
3+
"@microsoft/microsoft-graph-types": "^0.4.1",
4+
"@microsoft/microsoft-graph-types-beta": "microsoftgraph/msgraph-typescript-typings#beta",
5+
"@microsoft/microsoft-graph-client": "^0.4.1",
6+
"@types/chai": "^3.5.1",
7+
"chai": "^3.5.0"
8+
}
9+
}

spec/types/people.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {assert} from 'chai'
2+
3+
import { getClient, randomString } from "./test-helper"
4+
import { Person } from '@microsoft/microsoft-graph-types-beta'
5+
6+
declare const describe, it;
7+
8+
describe('People', function() {
9+
this.timeout(10*1000);
10+
it('Fetch a list of people', function() {
11+
return getClient().api("https://graph.microsoft.com/beta/me/people/").get().then((json) => {
12+
const person = json.value[0] as Person;
13+
assert.isDefined(person.displayName);
14+
assert.isDefined(person.surname);
15+
assert.isDefined(person.id);
16+
17+
assert.isUndefined(person['invalidPropertyName']);
18+
return Promise.resolve();
19+
});
20+
});
21+
});

spec/types/test-helper.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AccessToken } from "./secrets"
2+
import { Client } from "@microsoft/microsoft-graph-client"
3+
4+
export function getClient():Client {
5+
return Client.init({
6+
authProvider: (done) => {
7+
done(null, AccessToken);
8+
}
9+
});
10+
}
11+
12+
13+
export function randomString () {
14+
return Math.random().toString(36).substring(7);
15+
}

0 commit comments

Comments
 (0)