Skip to content

Commit eb8d87e

Browse files
Merge pull request #84 from microsoftgraph/fix-failing-types-unit-test
Fix failing unit tests under types directory, Remove hardcoded request urls, Remove beta endpoint usage and Use sdk modules from repo instead of using published package modules (this is correct way to test the code that is being changed)
2 parents ea37db8 + e6a46e1 commit eb8d87e

File tree

10 files changed

+2063
-276
lines changed

10 files changed

+2063
-276
lines changed

package-lock.json

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

spec/types/OneNote.ts

Lines changed: 50 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,62 @@
1-
import {assert} from 'chai'
1+
import { assert } from 'chai'
22

33
import { getClient, randomString } from "./test-helper"
4-
import { Notebook, Section, Page } from '@microsoft/microsoft-graph-types-beta'
4+
import { Notebook, OnenoteSection, OnenotePage } from '@microsoft/microsoft-graph-types-beta'
55

66
declare const describe, it;
77

8-
describe('OneNote', function() {
9-
this.timeout(20*1000);
10-
let notebook:Notebook = {
11-
name: "Sample notebook - " + randomString()
12-
};
8+
describe('OneNote', function () {
9+
this.timeout(20 * 1000);
10+
let notebook: Notebook = {
11+
displayName: "Sample notebook - " + randomString()
12+
};
1313

14-
let section:Section = {
15-
name: "Sample section - " + randomString()
16-
}
14+
let section: OnenoteSection = {
15+
displayName: "Sample section - " + randomString()
16+
}
1717

18-
let createdPage:Page;
19-
const PageContent = "Sample page content - " + randomString();
18+
let createdPage: OnenotePage;
19+
const PageContent = "Sample page content - " + randomString();
2020

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']);
21+
it('Create a OneNote notebook', function () {
22+
return getClient().api("/me/onenote/notebooks").post(notebook).then((json) => {
23+
const createdNotebook = json as Notebook;
24+
assert.isDefined(createdNotebook.id);
25+
assert.equal(notebook.displayName, createdNotebook.displayName);
26+
assert.isUndefined(createdNotebook['invalidPropertyName']);
7227

28+
// if this passes, use this notebook in the following tests
29+
notebook = createdNotebook;
7330
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']);
31+
});
32+
});
33+
34+
it('Create a OneNote section in a Notebook', function () {
35+
return getClient().api(`/me/onenote/notebooks/${notebook.id}/sections`).post(section).then((json) => {
36+
const createdSection = json as OnenoteSection;
37+
assert.isDefined(createdSection.id);
38+
assert.equal(section.displayName, createdSection.displayName);
39+
assert.isUndefined(createdSection['invalidPropertyName']);
40+
41+
// if this passes, use this notebook in the following tests
42+
section = createdSection;
8943
return Promise.resolve();
90-
});
91-
})
44+
45+
});
46+
});
47+
48+
it('Create a OneNote page in a section with basic text content', function () {
49+
return getClient()
50+
.api(`/me/onenote/sections/${section.id}/pages`)
51+
.header("Content-Type", "text/html")
52+
.post(PageContent)
53+
.then((json) => {
54+
createdPage = json as OnenotePage;
55+
assert.isDefined(createdPage.id);
56+
assert.isDefined(createdPage.contentUrl);
57+
assert.isUndefined(createdPage['invalidPropertyName']);
58+
59+
return Promise.resolve();
60+
});
61+
});
9262
});

spec/types/delta-query.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { getClient, randomString } from "./test-helper"
66

77
declare const describe, it;
88

9-
describe('Delta Query', function() {
10-
this.timeout(10*1000);
9+
describe('Delta Query', function () {
10+
this.timeout(10 * 1000);
1111
let today = new Date();
1212
let tomorrow = new Date(today.getTime() + 1 * 24 * 60 * 60 * 1000);
1313
let nextWeek = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1000);
1414

15-
let deltaLink:string;
15+
let deltaLink: string;
1616

17-
let mockEvent:Event = {
17+
let mockEvent: Event = {
1818
"originalStartTimeZone": tomorrow.toISOString(),
1919
"originalEndTimeZone": tomorrow.toISOString(),
2020
"reminderMinutesBeforeStart": 99,
@@ -23,14 +23,13 @@ describe('Delta Query', function() {
2323
}
2424

2525

26-
it('Gets the delta link for the initial calendar view list', function() {
26+
it('Gets the delta link for the initial calendar view list', function () {
2727
return getClient()
2828
.api("/me/calendarview/delta")
2929
.query({
30-
"startdatetime" : today.toISOString(),
30+
"startdatetime": today.toISOString(),
3131
"enddatetime": nextWeek.toISOString()
3232
})
33-
.version("beta")
3433
.get()
3534
.then((res) => {
3635
return getClient()
@@ -42,18 +41,18 @@ describe('Delta Query', function() {
4241
});
4342
});
4443

45-
it('Creates a calendar event to see changes in the delta response', function() {
44+
it('Creates a calendar event to see changes in the delta response', function () {
4645
return getClient()
4746
.api('/me/events')
4847
.post(mockEvent);
4948
});
5049

51-
it('Uses delta token to see changed calendar view', function() {
50+
it('Uses delta token to see changed calendar view', function () {
5251
return getClient()
5352
.api(deltaLink)
5453
.get()
5554
.then((res) => {
56-
let events:Event[] = res.value;
55+
let events: Event[] = res.value;
5756
for (let event of events) {
5857
if (event.subject == mockEvent.subject) {
5958
return Promise.resolve();

spec/types/excel.ts

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,57 @@ declare const describe, it;
88

99
const ExcelFilename = `empty-spreadsheet-${randomString()}.xlsx`;
1010

11-
describe('Excel', function() {
12-
this.timeout(10*1000);
13-
it('Uploads an Excel file to OneDrive', function() {
14-
15-
let file = fs.readFileSync('./spec/types/empty-spreadsheet.xlsx');
16-
return getClient()
17-
.api(`/me/drive/root/children/${ExcelFilename}/content`)
18-
.put(file);
19-
});
20-
21-
it('Lists the worksheets in an excel file', function() {
22-
return getClient()
23-
.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets`)
24-
.get()
25-
.then((res) => {
26-
let worksheets = res.value as WorkbookWorksheet[];
27-
let sheet1 = worksheets[0];
28-
assert.isNumber(sheet1.position);
29-
assert.isString(sheet1.visibility);
30-
assert.isString(sheet1.id);
31-
assert.isUndefined(sheet1['random fake property that should be null']);
32-
return Promise.resolve();
33-
})
34-
})
35-
36-
it('Updates workbook worksheet range', function() {
37-
let sampleData:WorkbookRange = {
38-
values: [
39-
['cell a1', 'cell a2'],
40-
['cell b1', 'cell b2']
41-
]
42-
};
43-
return getClient()
44-
.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range(address='A1:B2')`)
45-
.patch(sampleData)
46-
})
47-
48-
it('GETs the used range of the worksheet', function() {
49-
return getClient()
50-
.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range/usedrange`)
51-
.get()
52-
.then((res:WorkbookRange) => {
53-
assert.isNumber(res.cellCount);
54-
assert.isString(res.address);
55-
assert.isUndefined(res['other prop'])
56-
})
57-
})
11+
describe('Excel', function () {
12+
this.timeout(10 * 1000);
13+
beforeEach((done) => {
14+
setTimeout(function () {
15+
done();
16+
}, 1000);
17+
});
18+
it('Uploads an Excel file to OneDrive', function () {
19+
20+
let file = fs.readFileSync('./spec/types/empty-spreadsheet.xlsx');
21+
return getClient()
22+
.api(`/me/drive/root/children/${ExcelFilename}/content`)
23+
.put(file);
24+
});
25+
26+
it('Lists the worksheets in an excel file', function () {
27+
return getClient()
28+
.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets`)
29+
.get()
30+
.then((res) => {
31+
let worksheets = res.value as WorkbookWorksheet[];
32+
let sheet1 = worksheets[0];
33+
assert.isNumber(sheet1.position);
34+
assert.isString(sheet1.visibility);
35+
assert.isString(sheet1.id);
36+
assert.isUndefined(sheet1['random fake property that should be null']);
37+
return Promise.resolve();
38+
})
39+
})
40+
41+
it('Updates workbook worksheet range', function () {
42+
let sampleData: WorkbookRange = {
43+
values: [
44+
['cell a1', 'cell a2'],
45+
['cell b1', 'cell b2']
46+
]
47+
};
48+
return getClient()
49+
.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range(address='A1:B2')`)
50+
.patch(sampleData)
51+
})
52+
53+
54+
it('GETs the used range of the worksheet', function () {
55+
return getClient()
56+
.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range/usedrange`)
57+
.get()
58+
.then((res: WorkbookRange) => {
59+
assert.isNumber(res.cellCount);
60+
assert.isString(res.address);
61+
assert.isUndefined(res['other prop'])
62+
})
63+
})
5864
});

spec/types/groups.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ import { Group } from '@microsoft/microsoft-graph-types'
55

66
declare const describe, it;
77

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);
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("/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);
1616

17-
assert.isUndefined(group['invalidPropertyName']);
18-
return Promise.resolve();
19-
});
20-
});
17+
assert.isUndefined(group['invalidPropertyName']);
18+
return Promise.resolve();
19+
});
20+
});
2121

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-
};
22+
it('Create a group and validate properties were set', function () {
23+
const group: Group = {
24+
displayName: randomString(),
25+
description: randomString(),
26+
groupTypes: [
27+
"Unified"
28+
],
29+
mailEnabled: true,
30+
mailNickname: randomString(),
31+
securityEnabled: true
32+
};
3333

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();
34+
return getClient().api("/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+
});
4142
});
42-
});
4343
});

0 commit comments

Comments
 (0)