Skip to content

Commit 584c60f

Browse files
U-FAREAST\ramguptU-FAREAST\ramgupt
U-FAREAST\ramgupt
authored and
U-FAREAST\ramgupt
committed
Add tests
1 parent 2e745db commit 584c60f

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed

sample.png

2.13 KB
Loading

spec/types/miscellaneous.ts

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
Tests in this file tries to cover functionality in Graph API, it may not contain exhaustive end points. Functionality
3+
includes OData features, GET on complexType, GET on entity, POST an entity, POST an action etc..
4+
5+
For the tests to run, make sure that all the app permissions are there.
6+
*/
7+
8+
import { assert } from 'chai'
9+
import { getClient, randomString } from "./test-helper"
10+
11+
12+
declare const describe, it;
13+
14+
describe('Fetch messages', function() {
15+
this.timeout(10*1000);
16+
it('Fetch the messages', function(done) {
17+
return getClient().api("https://graph.microsoft.com/v1.0/me/messages").get((err, res) => {
18+
assert.isTrue(err === null);
19+
assert.isDefined(res['@odata.context']);
20+
assert.isDefined(res['@odata.nextLink']);
21+
assert.isDefined(res['value']);
22+
done();
23+
});
24+
});
25+
26+
it('Fetch the messages with $top', function(done) {
27+
return getClient().api("https://graph.microsoft.com/v1.0/me/messages?$top=5").get((err, res) => {
28+
assert.isTrue(err === null);
29+
assert.isDefined(res['@odata.context']);
30+
assert.isDefined(res['@odata.nextLink']);
31+
assert.isDefined(res['value']);
32+
assert.isTrue(res.value.length == 5);
33+
done();
34+
});
35+
});
36+
37+
it('Fetch the messages with $select', function(done) {
38+
return getClient().api("https://graph.microsoft.com/v1.0/me/messages?$select=createdDateTime").get((err, res) => {
39+
assert.isTrue(err === null);
40+
assert.isDefined(res['@odata.context']);
41+
assert.isDefined(res['@odata.nextLink']);
42+
assert.isDefined(res['value']);
43+
assert.isDefined(res.value[0]['createdDateTime']);
44+
done();
45+
});
46+
});
47+
});
48+
49+
describe('GET/PATCH mailBoxSettings', function() {
50+
this.timeout(10*1000);
51+
it('GET mailBoxSettings', function(done) {
52+
return getClient().api("https://graph.microsoft.com/v1.0/me/mailboxSettings").get((err, res) => {
53+
assert.isDefined(res['@odata.context']);
54+
assert.isDefined(res['archiveFolder']);
55+
assert.isDefined(res['timeZone']);
56+
assert.isDefined(res['automaticRepliesSetting']);
57+
assert.isDefined(res['language']);
58+
assert.isDefined(res['workingHours']);
59+
done();
60+
});
61+
});
62+
63+
it('PATCH mailBoxSettings', function(done) {
64+
return getClient().api("https://graph.microsoft.com/v1.0/me/mailboxSettings").patch({"timeZone": "India Standard Time"}, (err, res) => {
65+
assert.isDefined(res['@odata.context']);
66+
assert.isDefined(res['timeZone']);
67+
assert.isTrue(res['timeZone'] == 'India Standard Time');
68+
done();
69+
});
70+
});
71+
});
72+
73+
describe('Fetch inbox folder', function() {
74+
this.timeout(10*1000);
75+
it('GET me/mailfolders/inbox', function(done) {
76+
return getClient().api("https://graph.microsoft.com/v1.0/me/mailfolders/inbox").get((err, res) => {
77+
assert.isTrue(err === null);
78+
assert.isDefined(res['@odata.context']);
79+
assert.isDefined(res['id']);
80+
assert.isDefined(res['displayName']);
81+
assert.isDefined(res['parentFolderId']);
82+
assert.isDefined(res['childFolderCount']);
83+
assert.isDefined(res['unreadItemCount']);
84+
assert.isDefined(res['totalItemCount']);
85+
done();
86+
});
87+
});
88+
});
89+
90+
describe('Fetch users and groups', function() {
91+
this.timeout(10*1000);
92+
it('GET users/{id}', function(done) {
93+
return getClient().api("https://graph.microsoft.com/v1.0/users").get((err, res) => {
94+
assert.isTrue(err === null);
95+
assert.isDefined(res);
96+
assert.isDefined(res['value']);
97+
const id = res['value'][0]['id'];
98+
return getClient().api("https://graph.microsoft.com/v1.0/users/" + id).get((err, res) => {
99+
assert.isTrue(err === null);
100+
assert.isDefined(res);
101+
assert.isTrue(res['id'] == id);
102+
done();
103+
});
104+
});
105+
});
106+
107+
it('GET groups/{id}', function(done) {
108+
return getClient().api("https://graph.microsoft.com/v1.0/groups").get((err, res) => {
109+
assert.isTrue(err === null);
110+
assert.isDefined(res);
111+
const id = res['value'][0]['id'];
112+
return getClient().api("https://graph.microsoft.com/v1.0/groups/" + id).get((err, res) => {
113+
assert.isTrue(err === null);
114+
assert.isDefined(res);
115+
assert.isTrue(res['id'] == id);
116+
done();
117+
});
118+
});
119+
});
120+
});
121+
122+
describe('Test for actions and functions', function() {
123+
this.timeout(10*1000);
124+
it('GET me/findrooms', function(done) {
125+
return getClient().api("https://graph.microsoft.com/beta/me/findRooms").get((err, res) => {
126+
assert.isTrue(err === null);
127+
assert.isDefined(res['@odata.context']);
128+
assert.isDefined(res['value']);
129+
done();
130+
});
131+
});
132+
133+
it('POST me/getMailTips', function(done) {
134+
return getClient().api("https://graph.microsoft.com/beta/me/getMailTips").post({
135+
"EmailAddresses": [
136+
137+
138+
],
139+
"MailTipsOptions": "automaticReplies, mailboxFullStatus"
140+
}, (err, res) => {
141+
assert.isTrue(err === null);
142+
assert.isDefined(res['@odata.context']);
143+
assert.isDefined(res['value']);
144+
assert.isUndefined(res['error']);
145+
done();
146+
});
147+
});
148+
});
149+
150+
describe('Test for GET and PUT binary data', function() {
151+
this.timeout(10*1000);
152+
it('PUT me/photo', function(done) {
153+
const fs = require("fs");
154+
var nb = fs.readFileSync('sample.png');
155+
return getClient().api("https://graph.microsoft.com/v1.0/me/photo/$value").put(nb, (err, res) => {
156+
assert.isTrue(err === null);
157+
done();
158+
});
159+
});
160+
161+
it('GET me/photo', function(done) {
162+
return getClient().api("https://graph.microsoft.com/v1.0/me/photo/$value").get((err, res) => {
163+
assert.isTrue(err === null);
164+
done();
165+
});
166+
});
167+
});
168+
169+
170+
171+
172+

0 commit comments

Comments
 (0)