Skip to content

Commit 60270db

Browse files
U-FAREAST\ramguptU-FAREAST\ramgupt
authored andcommitted
Add tests
1 parent 2e745db commit 60270db

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

sample.png

2.13 KB
Loading

spec/types/miscellaneous.ts

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

0 commit comments

Comments
 (0)