@manyos/smileconnect-api 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/.github/workflows/nodejs.yml +26 -0
  2. package/CHANGELOG.md +75 -0
  3. package/Dockerfile +21 -0
  4. package/README.md +1 -0
  5. package/app.js +316 -0
  6. package/conf/clients.json +2491 -0
  7. package/conf/mapping.json +1048 -0
  8. package/conf/scripts/p1.js +11 -0
  9. package/conf/scripts/p2.js +1 -0
  10. package/conf/scripts/p3.js +1 -0
  11. package/conf/scripts/p4.js +2 -0
  12. package/conf/scripts/script1.js +2 -0
  13. package/conf/scripts/script2.js +2 -0
  14. package/conf/scripts/script3.js +2 -0
  15. package/controller/cmdbobjectController.js +291 -0
  16. package/controller/eventLogController.js +78 -0
  17. package/controller/orgdataController.js +440 -0
  18. package/controller/relatedObjectsController.js +194 -0
  19. package/controller/scriptController.js +213 -0
  20. package/controller/taskController.js +368 -0
  21. package/controller/templateController.js +97 -0
  22. package/controller/ticketCIRelationController.js +522 -0
  23. package/controller/ticketController.js +329 -0
  24. package/controller/ticketWorkLogController.js +195 -0
  25. package/docs/.gitattributes +48 -0
  26. package/docs/404.html +13 -0
  27. package/docs/CNAME +1 -0
  28. package/docs/Gemfile +7 -0
  29. package/docs/Gemfile.lock +249 -0
  30. package/docs/_config.yml +257 -0
  31. package/docs/_data/SocialNetworks.yml +92 -0
  32. package/docs/_data/ui-text.yml +494 -0
  33. package/docs/_includes/disqus.html +17 -0
  34. package/docs/_includes/ext-css.html +7 -0
  35. package/docs/_includes/ext-js.html +7 -0
  36. package/docs/_includes/fb-comment.html +14 -0
  37. package/docs/_includes/footer-minimal.html +16 -0
  38. package/docs/_includes/footer-scripts.html +32 -0
  39. package/docs/_includes/footer.html +51 -0
  40. package/docs/_includes/google_analytics.html +14 -0
  41. package/docs/_includes/gtag.html +11 -0
  42. package/docs/_includes/gtm_body.html +6 -0
  43. package/docs/_includes/gtm_head.html +9 -0
  44. package/docs/_includes/head.html +131 -0
  45. package/docs/_includes/header.html +76 -0
  46. package/docs/_includes/just_comments.html +4 -0
  47. package/docs/_includes/matomo.html +17 -0
  48. package/docs/_includes/nav.html +57 -0
  49. package/docs/_includes/social-share.html +42 -0
  50. package/docs/_includes/staticman-comment.html +22 -0
  51. package/docs/_includes/staticman-comments.html +81 -0
  52. package/docs/_layouts/base.html +35 -0
  53. package/docs/_layouts/default.html +9 -0
  54. package/docs/_layouts/minimal.html +26 -0
  55. package/docs/_layouts/page.html +26 -0
  56. package/docs/_layouts/post.html +82 -0
  57. package/docs/_posts/2015-02-28-test-markdown.md +77 -0
  58. package/docs/aboutme.md +18 -0
  59. package/docs/css/bootstrap-social.css +147 -0
  60. package/docs/css/bootstrap-theme.css +476 -0
  61. package/docs/css/bootstrap-theme.css.map +1 -0
  62. package/docs/css/bootstrap-theme.min.css +5 -0
  63. package/docs/css/bootstrap.css +6566 -0
  64. package/docs/css/bootstrap.css.map +1 -0
  65. package/docs/css/bootstrap.min.css +5 -0
  66. package/docs/css/main-minimal.css +13 -0
  67. package/docs/css/main.css +788 -0
  68. package/docs/css/normalize.css +427 -0
  69. package/docs/css/pygment_highlights.css +61 -0
  70. package/docs/css/staticman.css +180 -0
  71. package/docs/eventlog/events.md +65 -0
  72. package/docs/feed.xml +24 -0
  73. package/docs/general/architecture.md +10 -0
  74. package/docs/general/config.md +192 -0
  75. package/docs/general/field-management.md +119 -0
  76. package/docs/general/release-notes.md +9 -0
  77. package/docs/getting-started.md +19 -0
  78. package/docs/howto/cmdbobjects.md +339 -0
  79. package/docs/howto/incident-worklogs.md +186 -0
  80. package/docs/howto/incidents.md +244 -0
  81. package/docs/howto/sample-config.md +518 -0
  82. package/docs/howto/token.md +71 -0
  83. package/docs/howto/worklog-attachment.md +113 -0
  84. package/docs/img/404-southpark.jpg +0 -0
  85. package/docs/img/architecture.jpeg +0 -0
  86. package/docs/img/attachment-upload.png +0 -0
  87. package/docs/img/avatar-icon.png +0 -0
  88. package/docs/img/bgimage.png +0 -0
  89. package/docs/img/gb-isapi.jpg +0 -0
  90. package/docs/img/install-steps.gif +0 -0
  91. package/docs/img/workflow.png +0 -0
  92. package/docs/index.md +41 -0
  93. package/docs/installation.md +123 -0
  94. package/docs/js/bootstrap.js +2306 -0
  95. package/docs/js/bootstrap.min.js +7 -0
  96. package/docs/js/jquery-1.11.2.min.js +4 -0
  97. package/docs/js/main.js +140 -0
  98. package/docs/js/staticman.js +54 -0
  99. package/docs/openapi.json +15097 -0
  100. package/docs/postinstall.md +169 -0
  101. package/docs/preinstall.md +19 -0
  102. package/docs/spec/index.html +24 -0
  103. package/docs/staticman.yml +110 -0
  104. package/docs/tags.html +34 -0
  105. package/docs/workflow.md +127 -0
  106. package/nodemon.json +3 -0
  107. package/package.json +46 -0
  108. package/routes/appConfigRoutes.js +352 -0
  109. package/routes/ciRelationRoutes.js +38 -0
  110. package/routes/cmdbObjectRoutes.js +154 -0
  111. package/routes/organisationRoutes.js +121 -0
  112. package/routes/peopleRelationRoutes.js +38 -0
  113. package/routes/personRoutes.js +131 -0
  114. package/routes/supportgroupRoutes.js +122 -0
  115. package/routes/taskRoutes.js +306 -0
  116. package/routes/templateRoutes.js +67 -0
  117. package/routes/ticketRoutes.js +181 -0
  118. package/routes/ticketWorkLogRoutes.js +185 -0
  119. package/screwdriver.yaml +52 -0
  120. package/test/appTest.js +3 -0
  121. package/test/changeTest.js +541 -0
  122. package/test/cmdbobjectTest.js +167 -0
  123. package/test/files/logo.png +0 -0
  124. package/test/incidentTest.js +539 -0
  125. package/test/orgdataTest.js +156 -0
  126. package/test/problemTest.js +512 -0
  127. package/test/templateTest.js +80 -0
  128. package/test/testUtils.js +21 -0
  129. package/test/workorderTest.js +544 -0
  130. package/util/arquery.js +416 -0
  131. package/util/auth.js +37 -0
  132. package/util/cache.service.js +52 -0
  133. package/util/config.js +361 -0
  134. package/util/constants.js +73 -0
  135. package/util/mappingUtil.js +96 -0
  136. package/util/paramHelper.js +43 -0
  137. package/util/relationUtil.js +63 -0
  138. package/util/responsehandler.js +92 -0
  139. package/util/schemas/clientConfigSchema.js +180 -0
  140. package/util/schemas/fieldMappingSchema.js +211 -0
  141. package/util/searchUtil.js +148 -0
@@ -0,0 +1,80 @@
1
+ const assert = require('chai').assert;
2
+ let chai = require('chai');
3
+ let chaiHttp = require('chai-http');
4
+ let should = chai.should();
5
+ let server = require('../app');
6
+ const TestUtils = require('./testUtils')
7
+ require('dotenv').config();
8
+ const path = require('path');
9
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
10
+
11
+ //Integrations Tests here
12
+
13
+ chai.use(chaiHttp);
14
+
15
+ function checkTemplate(template) {
16
+ template.id.should.be.a('string');
17
+ template.id.length.should.be.above(0);
18
+ template.name.should.be.a('string');
19
+ template.name.length.should.be.above(0);
20
+ }
21
+
22
+ describe('Integration Tests - Templates', function () {
23
+ let authUser = {'id':process.env.TEST_ID, 'secret':process.env.TEST_SECRET};
24
+
25
+ console.log('authuser', authUser);
26
+
27
+ before((done) => {
28
+
29
+ // Authenticate the user to get a token
30
+ TestUtils.authenticateUser(authUser, server)
31
+ .then((accessToken) => {
32
+ // Keep the token on the user so we can use it in the tests
33
+ authUser.access_token = accessToken;
34
+ return done();
35
+ })
36
+ .catch((err) => done(err));
37
+ });
38
+
39
+ const templateTypes = ['incidents', 'changes', 'problems', 'workorders', 'tasks'];
40
+
41
+ describe('Templates', function () {
42
+
43
+ templateTypes.forEach(templateType => {
44
+ let templateId = '';
45
+ it (`it should get all ${templateType} templates`, function (done) {
46
+ this.timeout(5000);
47
+ chai.request(server)
48
+ .get(`/v1/templates/${templateType}`)
49
+ .set('Authorization', 'Bearer ' + authUser.access_token)
50
+ .end(function(err, res) {
51
+ res.should.have.status(200);
52
+ res.body.data.should.be.a('array');
53
+ res.body.data.length.should.be.above(0);
54
+ const template0 = res.body.data[0];
55
+ checkTemplate(template0);
56
+ templateId = template0.id;
57
+ done();
58
+ })
59
+ })
60
+
61
+ it (`it should get a specific ${templateType} template`, function (done) {
62
+ this.timeout(5000);
63
+ chai.request(server)
64
+ .get(`/v1/templates/${templateType}/${templateId}`)
65
+ .set('Authorization', 'Bearer ' + authUser.access_token)
66
+ .end(function(err, res) {
67
+ res.should.have.status(200);
68
+ res.body.data.should.be.a('object');
69
+ const template0 = res.body.data;
70
+ checkTemplate(template0);
71
+ templateId = template0.id;
72
+ done();
73
+ })
74
+ })
75
+ });
76
+ })
77
+
78
+
79
+
80
+ })
@@ -0,0 +1,21 @@
1
+ let chai = require('chai');
2
+ const expect = chai.expect;
3
+
4
+ this.authenticateUser = (user, app) =>
5
+ new Promise((resolve, reject) => {
6
+ chai.request('https://sso.manyos.it')
7
+ .post('/auth/realms/itsmproxy/protocol/openid-connect/token')
8
+ .auth(user.id, user.secret)
9
+ .type('form')
10
+ .send({
11
+ 'grant_type': 'client_credentials'
12
+ })
13
+ .end((err, res) => {
14
+ expect(res).to.have.status(200);
15
+ if (err) {
16
+ return reject(err);
17
+ }
18
+ return resolve(res.body.access_token);
19
+ });
20
+ });
21
+
@@ -0,0 +1,544 @@
1
+ const assert = require('chai').assert;
2
+ let chai = require('chai');
3
+ let chaiHttp = require('chai-http');
4
+ let should = chai.should();
5
+ let server = require('../app');
6
+ const TestUtils = require('./testUtils')
7
+ require('dotenv').config();
8
+
9
+ //Integrations Tests here
10
+
11
+ chai.use(chaiHttp);
12
+
13
+ describe('Integration Tests - Workorders', function () {
14
+ let workorder;
15
+
16
+ let authUser = {'id':process.env.TEST_ID, 'secret':process.env.TEST_SECRET};
17
+
18
+ before((done) => {
19
+
20
+ // Authenticate the user to get a token
21
+ TestUtils.authenticateUser(authUser, server)
22
+ .then((accessToken) => {
23
+ // Keep the token on the user so we can use it in the tests
24
+ authUser.access_token = accessToken;
25
+ return done();
26
+ })
27
+ .catch((err) => done(err));
28
+ });
29
+
30
+ /*
31
+ */
32
+
33
+ describe('POST Workorder', function () {
34
+ it ('it should create a spezific workorder', function (done) {
35
+ this.timeout(5000);
36
+ chai.request(server)
37
+ .post('/v1/workorders')
38
+ .set('Authorization', 'Bearer ' + authUser.access_token)
39
+ .send({"data":{"summary":"hurst"}})
40
+ .end(function(err, res) {
41
+ res.should.have.status(200);
42
+ res.body.data.should.be.an('object');
43
+ res.body.data.should.have.property('summary');
44
+ res.body.data.should.have.property('id');
45
+ res.body.data.should.have.property('status');
46
+ workorder = res.body.data;
47
+ done();
48
+ })
49
+ })
50
+ })
51
+
52
+ describe('GET Workorders', function () {
53
+ it ('it should get all workorders', function (done) {
54
+ this.timeout(5000);
55
+ chai.request(server)
56
+ .get('/v1/workorders')
57
+ .set('Authorization', 'Bearer ' + authUser.access_token)
58
+ .end(function(err, res) {
59
+ res.should.have.status(200);
60
+ res.body.data.should.be.a('array');
61
+ res.body.data.length.should.be.above(0);
62
+ done();
63
+ })
64
+ })
65
+
66
+ it ('it should get a spezific workorder by id', function (done) {
67
+ this.timeout(5000);
68
+ chai.request(server)
69
+ .get(`/v1/workorders/${workorder.id}`)
70
+ .set('Authorization', 'Bearer ' + authUser.access_token)
71
+ .end(function(err, res) {
72
+ res.should.have.status(200);
73
+ res.body.data.should.be.an('object');
74
+ res.body.data.should.have.property('summary');
75
+ res.body.data.should.have.property('id');
76
+ res.body.data.should.have.property('status');
77
+ res.body.data.summary.should.equal(workorder.summary);
78
+ done();
79
+ })
80
+ })
81
+
82
+ it ('it should search for a workorder with included objects', function (done) {
83
+ this.timeout(50000);
84
+ chai.request(server)
85
+ .post('/v1/workorders/search?includeObjects=true')
86
+ .set('Authorization', 'Bearer ' + authUser.access_token)
87
+ .send({
88
+ "searchString":`'id'=\"${workorder.id}\"`
89
+ })
90
+ .end(function(err, res) {
91
+ res.should.have.status(200);
92
+ res.body.data.should.be.an('array');
93
+ res.body.data.length.should.be.above(0);
94
+
95
+ done();
96
+ })
97
+ })
98
+
99
+ it ('it should get a spezific workorder by id and included objects', function (done) {
100
+ this.timeout(5000);
101
+ chai.request(server)
102
+ .get(`/v1/workorders/${workorder.id}?includeObjects=true`)
103
+ .set('Authorization', 'Bearer ' + authUser.access_token)
104
+ .end(function(err, res) {
105
+ res.should.have.status(200);
106
+ res.body.data.should.be.an('object');
107
+ res.body.data.should.have.property('summary');
108
+ res.body.data.should.have.property('id');
109
+ res.body.data.should.have.property('status');
110
+
111
+ res.body.included.should.be.an('object');
112
+ res.body.included.should.have.property('persons');
113
+ res.body.included.persons.should.be.an('array');
114
+ res.body.included.persons.length.should.be.above(0);
115
+
116
+ res.body.included.should.have.property('organisations');
117
+ res.body.included.organisations.should.be.an('array');
118
+ //res.body.included.organisations.length.should.be.above(0);
119
+
120
+ res.body.included.should.have.property('supportgroups');
121
+ res.body.included.supportgroups.should.be.an('array');
122
+ res.body.included.supportgroups.length.should.be.above(0);
123
+ done();
124
+ })
125
+ })
126
+ })
127
+
128
+
129
+ describe ('Workorder Update', function () {
130
+ it ('it should close a spezific workorder by id', function (done) {
131
+ this.timeout(5000);
132
+ chai.request(server)
133
+ .put(`/v1/workorders/${workorder.id}`)
134
+ .set('Authorization', 'Bearer ' + authUser.access_token)
135
+ .send({"data":{"status":"Completed", "statusReason": "Successful"}})
136
+ .end(function(err, res) {
137
+ res.should.have.status(200);
138
+ res.body.data.should.be.an('object');
139
+ res.body.data.should.have.property('summary');
140
+ res.body.data.should.have.property('id');
141
+ res.body.data.should.have.property('status');
142
+ res.body.data.status.should.equal("Completed");
143
+ done();
144
+ })
145
+ })
146
+ })
147
+
148
+ describe ('Workorder Relations', function() {
149
+ it ('it should link a specific CI to the workorder', function (done) {
150
+ this.timeout(50000);
151
+ chai.request(server)
152
+ .put(`/v1/workorders/${workorder.id}?include=ciRelations`)
153
+ .set('Authorization', 'Bearer ' + authUser.access_token)
154
+ .send(
155
+ {
156
+ "data": {
157
+ "relations": {
158
+ "ciRelations":
159
+ [{
160
+ "ciId":"OI-94001f3f08b7415685fe72ec17f98f84",
161
+ "relationType":"Related to"
162
+ },
163
+ {
164
+ "ciId":"OI-a2c843b3e3d14eeaa74dcefd4fdcf808",
165
+ "relationType":"Related to"
166
+ }]
167
+ }
168
+ }
169
+ })
170
+ .end(function(err, res) {
171
+ res.should.have.status(200);
172
+ res.body.data.should.be.an('object');
173
+ res.body.data.should.have.property('summary');
174
+ res.body.data.should.have.property('id');
175
+ res.body.data.should.have.property('status');
176
+ res.body.data.should.have.property('relations');
177
+ res.body.data.relations.should.have.property('ciRelations');
178
+ res.body.data.relations.ciRelations.should.be.an('array');
179
+ res.body.data.relations.ciRelations.length.should.be.above(0);
180
+ done();
181
+ })
182
+ })
183
+
184
+ it ('it should link a wrong CI to the change', function (done) {
185
+ this.timeout(50000);
186
+ chai.request(server)
187
+ .put(`/v1/workorders/${workorder.id}?include=ciRelations`)
188
+ .set('Authorization', 'Bearer ' + authUser.access_token)
189
+ .send(
190
+ {
191
+ "data": {
192
+ "relations": {
193
+ "ciRelations":
194
+ [{
195
+ "ciId":"AGGarserver000PMIYWAPL1SMUB5AZxxx",
196
+ "relationType":"Related to"
197
+ }]
198
+ }
199
+ }
200
+ })
201
+ .end(function(err, res) {
202
+ res.should.have.status(500);
203
+ done();
204
+ })
205
+ })
206
+
207
+ it ('it should use a wrong relation type', function (done) {
208
+ this.timeout(50000);
209
+ chai.request(server)
210
+ .put(`/v1/workorders/${workorder.id}?include=ciRelations`)
211
+ .set('Authorization', 'Bearer ' + authUser.access_token)
212
+ .send(
213
+ {
214
+ "data": {
215
+ "relations": {
216
+ "ciRelations":
217
+ [{
218
+ "ciId":"AGGarserver000PMIYWAPL1SMUB5AZ",
219
+ "relationType":"RestoresX"
220
+ }]
221
+ }
222
+ }
223
+ })
224
+ .end(function(err, res) {
225
+ res.should.have.status(500);
226
+ done();
227
+ })
228
+ })
229
+
230
+ it ('it should link to a specific incident', function (done) {
231
+ this.timeout(50000);
232
+ chai.request(server)
233
+ .put(`/v1/workorders/${workorder.id}?include=ticketRelations`)
234
+ .set('Authorization', 'Bearer ' + authUser.access_token)
235
+ .send(
236
+ {
237
+ "data": {
238
+ "relations": {
239
+ "ticketRelations":
240
+ [{
241
+ "ticketId":"INC000000000335",
242
+ "relationType":"Related to",
243
+ "ticketType": "Incident"
244
+ }]
245
+ }
246
+ }
247
+ })
248
+ .end(function(err, res) {
249
+ res.should.have.status(200);
250
+ res.body.data.should.be.an('object');
251
+ res.body.data.should.have.property('summary');
252
+ res.body.data.should.have.property('id');
253
+ res.body.data.should.have.property('status');
254
+ res.body.data.should.have.property('relations');
255
+ res.body.data.relations.should.have.property('ticketRelations');
256
+ res.body.data.relations.ticketRelations.should.be.an('array');
257
+ res.body.data.relations.ticketRelations.length.should.be.above(0);
258
+ done();
259
+ })
260
+ })
261
+
262
+ })
263
+
264
+ describe('Workorder Worklogs', function () {
265
+ let worklog;
266
+ let attachmentUrl;
267
+ let attachmentUrl2;
268
+ let attachmentUrl3;
269
+ //const worklogBaseUri = `/v1/incidents/${incident.id}/worklogs`;
270
+
271
+ it('it should create a spezific workorder worklog', function (done) {
272
+ this.timeout(5000);
273
+ chai.request(server)
274
+ .post(`/v1/workorders/${workorder.id}/worklogs`)
275
+ .set('Authorization', 'Bearer ' + authUser.access_token)
276
+ .send({data: {summary: "Worklog Summary", text: "Worklog Text"}})
277
+ .end(function (err, res) {
278
+ res.should.have.status(200);
279
+ res.body.data.should.be.an('object');
280
+ res.body.data.should.have.property('summary');
281
+ res.body.data.should.have.property('text');
282
+ res.body.data.should.have.property('id');
283
+ worklog = res.body.data;
284
+ res.body.urls.should.be.an('object');
285
+
286
+ res.body.urls.should.have.property('attachmentUrl');
287
+ res.body.urls.should.have.property('attachmentUrl2');
288
+ res.body.urls.should.have.property('attachmentUrl3');
289
+ res.body.urls.should.have.property('self');
290
+ done();
291
+ })
292
+ })
293
+
294
+ it('it should read a spezific workorder worklog', function (done) {
295
+ this.timeout(5000);
296
+ chai.request(server)
297
+ .get(`/v1/workorders/${workorder.id}/worklogs/${worklog.id}`)
298
+ .set('Authorization', 'Bearer ' + authUser.access_token)
299
+ .end(function (err, res) {
300
+ res.should.have.status(200);
301
+ res.body.data.should.be.an('object');
302
+ res.body.data.should.have.property('summary');
303
+ res.body.data.should.have.property('text');
304
+ res.body.data.should.have.property('id');
305
+
306
+ res.body.data.summary.should.equal(worklog.summary);
307
+ res.body.data.text.should.equal(worklog.text);
308
+
309
+ res.body.urls.should.be.an('object');
310
+
311
+ res.body.urls.should.have.property('attachmentUrl');
312
+ res.body.urls.should.have.property('attachmentUrl2');
313
+ res.body.urls.should.have.property('attachmentUrl3');
314
+ res.body.urls.should.have.property('self');
315
+ attachmentUrl = res.body.urls.attachmentUrl;
316
+ attachmentUrl2 = res.body.urls.attachmentUrl2;
317
+ attachmentUrl3 = res.body.urls.attachmentUrl3;
318
+ done();
319
+ })
320
+ })
321
+
322
+ it('it should add an attachment to a worklog', function (done) {
323
+ this.timeout(5000);
324
+ chai.request(server)
325
+ .post(attachmentUrl)
326
+ .attach('file', 'test/files/logo.png', 'logo.png')
327
+ .set('Authorization', 'Bearer ' + authUser.access_token)
328
+ .end(function (err, res) {
329
+ res.should.have.status(200);
330
+ done();
331
+ })
332
+ })
333
+
334
+ it('it should add a 2nd attachment to a worklog', function (done) {
335
+ this.timeout(5000);
336
+ chai.request(server)
337
+ .post(attachmentUrl2)
338
+ .attach('file', 'test/files/logo.png', 'logo.png')
339
+ .set('Authorization', 'Bearer ' + authUser.access_token)
340
+ .end(function (err, res) {
341
+ res.should.have.status(200);
342
+ done();
343
+ })
344
+ })
345
+
346
+ it('it should add a 3rd attachment to a worklog', function (done) {
347
+ this.timeout(5000);
348
+ chai.request(server)
349
+ .post(attachmentUrl3)
350
+ .attach('file', 'test/files/logo.png', 'logo.png')
351
+ .set('Authorization', 'Bearer ' + authUser.access_token)
352
+ .end(function (err, res) {
353
+ res.should.have.status(200);
354
+ done();
355
+ })
356
+ })
357
+
358
+ it('it should read an attachment from a worklog', function (done) {
359
+ this.timeout(5000);
360
+ chai.request(server)
361
+ .get(attachmentUrl)
362
+ .set('Authorization', 'Bearer ' + authUser.access_token)
363
+ .end(function (err, res) {
364
+ res.should.have.status(200);
365
+ res.should.have.header('content-type', 'application/octet-stream');
366
+ res.should.have.header('content-disposition', 'attachment; filename=logo.png');
367
+ console.log(res.headers);
368
+ done();
369
+ })
370
+ })
371
+
372
+ it ('it should get all workorder worklogs', function (done) {
373
+ this.timeout(5000);
374
+ chai.request(server)
375
+ .get(`/v1/workorders/${workorder.id}/worklogs`)
376
+ .set('Authorization', 'Bearer ' + authUser.access_token)
377
+ .end(function(err, res) {
378
+ res.should.have.status(200);
379
+ res.body.data.should.be.a('array');
380
+ res.body.data.length.should.be.above(0);
381
+ done();
382
+ })
383
+ })
384
+ })
385
+
386
+ describe('Workorder Tasks', function () {
387
+ let task;
388
+ it ('it should create a spezific workorder task', function (done) {
389
+ this.timeout(5000);
390
+ chai.request(server)
391
+ .post(`/v1/workorders/${workorder.id}/tasks`)
392
+ .set('Authorization', 'Bearer ' + authUser.access_token)
393
+ .send({"data":{"summary":"task1"}})
394
+ .end(function(err, res) {
395
+ res.should.have.status(200);
396
+ res.body.data.should.be.an('object');
397
+ res.body.data.should.have.property('summary');
398
+ res.body.data.should.have.property('notes');
399
+ res.body.data.should.have.property('id');
400
+ task = res.body.data;
401
+ done();
402
+ })
403
+ })
404
+
405
+ it ('it should create a multiple workorder tasks at once', function (done) {
406
+ this.timeout(5000);
407
+ chai.request(server)
408
+ .post(`/v1/workorders/${workorder.id}/tasks`)
409
+ .set('Authorization', 'Bearer ' + authUser.access_token)
410
+ .send({
411
+ "data": [
412
+ {"summary":"task2"},
413
+ {"summary":"task3"}
414
+ ]
415
+ })
416
+ .end(function(err, res) {
417
+ res.should.have.status(200);
418
+ res.body.data.should.be.an('array');
419
+ res.body.data.length.should.be.eq(2);
420
+ done();
421
+ })
422
+ })
423
+
424
+ it ('it should create a single workorder tasks as array', function (done) {
425
+ this.timeout(5000);
426
+ chai.request(server)
427
+ .post(`/v1/workorders/${workorder.id}/tasks`)
428
+ .set('Authorization', 'Bearer ' + authUser.access_token)
429
+ .send({
430
+ "data": [
431
+ {"summary":"task2"}
432
+ ]
433
+ })
434
+ .end(function(err, res) {
435
+ res.should.have.status(200);
436
+ res.body.data.should.be.an('array');
437
+ res.body.data.length.should.be.eq(1);
438
+ done();
439
+ })
440
+ })
441
+
442
+ it ('it should get all workorder tasks', function (done) {
443
+ this.timeout(5000);
444
+ chai.request(server)
445
+ .get(`/v1/workorders/${workorder.id}/tasks`)
446
+ .set('Authorization', 'Bearer ' + authUser.access_token)
447
+ .end(function(err, res) {
448
+ res.should.have.status(200);
449
+ res.body.data.should.be.a('array');
450
+ res.body.data.length.should.be.eq(4);
451
+ done();
452
+ })
453
+ })
454
+
455
+ it ('it should get a specific workorder task', function (done) {
456
+ this.timeout(5000);
457
+ chai.request(server)
458
+ .get(`/v1/workorders/${workorder.id}/tasks/${task.id}`)
459
+ .set('Authorization', 'Bearer ' + authUser.access_token)
460
+ .end(function(err, res) {
461
+ res.should.have.status(200);
462
+ res.body.data.should.be.an('object');
463
+ res.body.data.should.have.property('summary');
464
+ res.body.data.should.have.property('notes');
465
+ res.body.data.should.have.property('id');
466
+ res.body.data.summary.should.equal(task.summary);
467
+ done();
468
+ })
469
+ })
470
+
471
+ it ('it should update a specific workorder task', function (done) {
472
+ this.timeout(5000);
473
+ chai.request(server)
474
+ .put(`/v1/workorders/${workorder.id}/tasks/${task.id}`)
475
+ .set('Authorization', 'Bearer ' + authUser.access_token)
476
+ .send({"data":{"summary":"Task1.1"}})
477
+ .end(function(err, res) {
478
+ res.should.have.status(200);
479
+ res.body.data.should.be.an('object');
480
+ res.body.data.should.have.property('summary');
481
+ res.body.data.should.have.property('notes');
482
+ res.body.data.should.have.property('id');
483
+ res.body.data.summary.should.equal("Task1.1");
484
+ done();
485
+ })
486
+ })
487
+
488
+ describe('Workorder Task Worklogs', function () {
489
+ let taskWorklog;
490
+ //const worklogBaseUri = `/v1/incidents/${incident.id}/worklogs`;
491
+
492
+ it('it should create a spezific workorder task worklog', function (done) {
493
+ this.timeout(5000);
494
+ chai.request(server)
495
+ .post(`/v1/workorders/${workorder.id}/tasks/${task.id}/worklogs`)
496
+ .set('Authorization', 'Bearer ' + authUser.access_token)
497
+ .send({data: {summary: "Worklog Summary", text: "Worklog Text"}})
498
+ .end(function (err, res) {
499
+ res.should.have.status(200);
500
+ res.body.data.should.be.an('object');
501
+ res.body.data.should.have.property('summary');
502
+ res.body.data.should.have.property('text');
503
+ res.body.data.should.have.property('id');
504
+ taskWorklog = res.body.data;
505
+ done();
506
+ })
507
+ })
508
+
509
+ it('it should read a spezific workorder task worklog', function (done) {
510
+ this.timeout(5000);
511
+ chai.request(server)
512
+ .get(`/v1/workorders/${workorder.id}/tasks/${task.id}/worklogs/${taskWorklog.id}`)
513
+ .set('Authorization', 'Bearer ' + authUser.access_token)
514
+ .end(function (err, res) {
515
+ res.should.have.status(200);
516
+ res.body.data.should.be.an('object');
517
+ res.body.data.should.have.property('summary');
518
+ res.body.data.should.have.property('text');
519
+ res.body.data.should.have.property('id');
520
+
521
+ res.body.data.summary.should.equal(taskWorklog.summary);
522
+ res.body.data.text.should.equal(taskWorklog.text);
523
+
524
+ //res.body.urls.should.have.nested.property('attachmentUrl');
525
+ done();
526
+ })
527
+ })
528
+
529
+ it ('it should get all workorder task worklogs', function (done) {
530
+ this.timeout(5000);
531
+ chai.request(server)
532
+ .get(`/v1/workorders/${workorder.id}/tasks/${task.id}/worklogs`)
533
+ .set('Authorization', 'Bearer ' + authUser.access_token)
534
+ .end(function(err, res) {
535
+ res.should.have.status(200);
536
+ res.body.data.should.be.a('array');
537
+ res.body.data.length.should.be.above(0);
538
+ done();
539
+ })
540
+ })
541
+ })
542
+ })
543
+
544
+ })