|
| 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 secrets.js. |
| 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 | + /* |
| 25 | + Following test assumes that number of messages exceed the default number for @odata.nextLink |
| 26 | + to exist |
| 27 | + */ |
| 28 | + it('Fetch the messages', function(done) { |
| 29 | + return getClient().api("https://graph.microsoft.com/v1.0/me/messages").get((err, res) => { |
| 30 | + assert.isTrue(err === null); |
| 31 | + assert.isDefined(res['@odata.context']); |
| 32 | + assert.isDefined(res['@odata.nextLink']); |
| 33 | + assert.isDefined(res['value']); |
| 34 | + done(); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + /* |
| 39 | + Following test assumes that number of messages exceed the default number for @odata.nextLink to |
| 40 | + exist |
| 41 | + */ |
| 42 | + it('Fetch the messages with $top', function(done) { |
| 43 | + return getClient().api("https://graph.microsoft.com/v1.0/me/messages?$top=5").get((err, res) => { |
| 44 | + assert.isTrue(err === null); |
| 45 | + assert.isDefined(res['@odata.context']); |
| 46 | + assert.isDefined(res['@odata.nextLink']); |
| 47 | + assert.isDefined(res['value']); |
| 48 | + assert.isTrue(res.value.length == 5); |
| 49 | + done(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + /* |
| 54 | + Following test assumes that number of messages exceed the default number for @odata.nextLink to exist |
| 55 | + */ |
| 56 | + it('Fetch the messages with $select', function(done) { |
| 57 | + return getClient().api("https://graph.microsoft.com/v1.0/me/messages?$select=createdDateTime").get((err, res) => { |
| 58 | + assert.isTrue(err === null); |
| 59 | + assert.isDefined(res['@odata.context']); |
| 60 | + assert.isDefined(res['@odata.nextLink']); |
| 61 | + assert.isDefined(res['value']); |
| 62 | + assert.isDefined(res.value[0]['createdDateTime']); |
| 63 | + done(); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
| 67 | + |
| 68 | +describe('GET/PATCH mailBoxSettings', function() { |
| 69 | + this.timeout(10*1000); |
| 70 | + it('GET mailBoxSettings', function(done) { |
| 71 | + return getClient().api("https://graph.microsoft.com/v1.0/me/mailboxSettings").get((err, res) => { |
| 72 | + assert.isDefined(res['@odata.context']); |
| 73 | + assert.isDefined(res['archiveFolder']); |
| 74 | + assert.isDefined(res['timeZone']); |
| 75 | + assert.isDefined(res['automaticRepliesSetting']); |
| 76 | + assert.isDefined(res['language']); |
| 77 | + assert.isDefined(res['workingHours']); |
| 78 | + done(); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + it('PATCH mailBoxSettings', function(done) { |
| 83 | + return getClient().api("https://graph.microsoft.com/v1.0/me/mailboxSettings").patch({"timeZone": "India Standard Time"}, (err, res) => { |
| 84 | + assert.isDefined(res['@odata.context']); |
| 85 | + assert.isDefined(res['timeZone']); |
| 86 | + assert.isTrue(res['timeZone'] == 'India Standard Time'); |
| 87 | + done(); |
| 88 | + }); |
| 89 | + }); |
| 90 | +}); |
| 91 | + |
| 92 | +describe('Fetch inbox folder', function() { |
| 93 | + this.timeout(10*1000); |
| 94 | + it('GET me/mailfolders/inbox', function(done) { |
| 95 | + return getClient().api("https://graph.microsoft.com/v1.0/me/mailfolders/inbox").get((err, res) => { |
| 96 | + assert.isTrue(err === null); |
| 97 | + assert.isDefined(res['@odata.context']); |
| 98 | + assert.isDefined(res['id']); |
| 99 | + assert.isDefined(res['displayName']); |
| 100 | + assert.isDefined(res['parentFolderId']); |
| 101 | + assert.isDefined(res['childFolderCount']); |
| 102 | + assert.isDefined(res['unreadItemCount']); |
| 103 | + assert.isDefined(res['totalItemCount']); |
| 104 | + done(); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
| 108 | + |
| 109 | +describe('Fetch users and groups', function() { |
| 110 | + this.timeout(10*1000); |
| 111 | + it('GET users/{id}', function(done) { |
| 112 | + return getClient().api("https://graph.microsoft.com/v1.0/users").get((err, res) => { |
| 113 | + assert.isTrue(err === null); |
| 114 | + assert.isDefined(res); |
| 115 | + assert.isDefined(res['value']); |
| 116 | + const id = res['value'][0]['id']; |
| 117 | + return getClient().api("https://graph.microsoft.com/v1.0/users/" + id).get((err, res) => { |
| 118 | + assert.isTrue(err === null); |
| 119 | + assert.isDefined(res); |
| 120 | + assert.isTrue(res['id'] == id); |
| 121 | + done(); |
| 122 | + }); |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + /* |
| 127 | + Following test assumes that a group has been made in the tenant. |
| 128 | + */ |
| 129 | + it('GET groups/{id}', function(done) { |
| 130 | + return getClient().api("https://graph.microsoft.com/v1.0/groups").get((err, res) => { |
| 131 | + assert.isTrue(err === null); |
| 132 | + assert.isDefined(res); |
| 133 | + const id = res['value'][0]['id']; |
| 134 | + return getClient().api("https://graph.microsoft.com/v1.0/groups/" + id).get((err, res) => { |
| 135 | + assert.isTrue(err === null); |
| 136 | + assert.isDefined(res); |
| 137 | + assert.isTrue(res['id'] == id); |
| 138 | + done(); |
| 139 | + }); |
| 140 | + }); |
| 141 | + }); |
| 142 | +}); |
| 143 | + |
| 144 | +describe('Test for actions and functions', function() { |
| 145 | + this.timeout(10*1000); |
| 146 | + it('GET me/findrooms', function(done) { |
| 147 | + return getClient().api("https://graph.microsoft.com/beta/me/findRooms").get((err, res) => { |
| 148 | + assert.isTrue(err === null); |
| 149 | + assert.isDefined(res['@odata.context']); |
| 150 | + assert.isDefined(res['value']); |
| 151 | + done(); |
| 152 | + }); |
| 153 | + }); |
| 154 | + |
| 155 | + it('POST me/getMailTips', function(done) { |
| 156 | + return getClient().api("https://graph.microsoft.com/beta/me/getMailTips").post({ |
| 157 | + "EmailAddresses": [ |
| 158 | + |
| 159 | + |
| 160 | + ], |
| 161 | + "MailTipsOptions": "automaticReplies, mailboxFullStatus" |
| 162 | + }, (err, res) => { |
| 163 | + assert.isTrue(err === null); |
| 164 | + assert.isDefined(res['@odata.context']); |
| 165 | + assert.isDefined(res['value']); |
| 166 | + assert.isUndefined(res['error']); |
| 167 | + done(); |
| 168 | + }); |
| 169 | + }); |
| 170 | +}); |
| 171 | + |
| 172 | +describe('Test for GET and PUT binary data', function() { |
| 173 | + this.timeout(10*1000); |
| 174 | + it('PUT me/photo', function(done) { |
| 175 | + const fs = require("fs"); |
| 176 | + var nb = fs.readFileSync('sample.png'); |
| 177 | + return getClient().api("https://graph.microsoft.com/v1.0/me/photo/$value").put(nb, (err, res) => { |
| 178 | + assert.isTrue(err === null); |
| 179 | + done(); |
| 180 | + }); |
| 181 | + }); |
| 182 | + |
| 183 | + it('GET me/photo', function(done) { |
| 184 | + return getClient().api("https://graph.microsoft.com/v1.0/me/photo/$value").get((err, res) => { |
| 185 | + assert.isTrue(err === null); |
| 186 | + done(); |
| 187 | + }); |
| 188 | + }); |
| 189 | +}); |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
0 commit comments