-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathjira-tests.js
1077 lines (868 loc) · 44.3 KB
/
jira-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { expect } from 'chai';
import rewire from 'rewire';
const JiraApi = rewire('../src/jira');
function getOptions(options) {
const actualOptions = options || {};
return {
protocol: actualOptions.protocol || 'http',
host: actualOptions.host || 'jira.somehost.com',
port: actualOptions.port || '8080',
username: actualOptions.username || 'someusername',
password: actualOptions.password || 'somepassword',
apiVersion: actualOptions.apiVersion || '2.0',
base: actualOptions.base || '',
strictSSL: actualOptions.hasOwnProperty('strictSSL') ? actualOptions.strictSSL : true,
request: actualOptions.request,
oauth: actualOptions.oauth || null,
intermediatePath: actualOptions.intermediatePath,
bearer: actualOptions.bearer || null,
ca: actualOptions.ca || null,
};
}
describe('Jira API Tests', () => {
describe('Constructor Tests', () => {
it('Constructor functions properly', () => {
const jira = new JiraApi(getOptions());
expect(jira.protocol).to.eql('http');
expect(jira.host).to.eql('jira.somehost.com');
expect(jira.port).to.eql('8080');
expect(jira.baseOptions.auth.user).to.eql('someusername');
expect(jira.baseOptions.auth.pass).to.eql('somepassword');
expect(jira.apiVersion).to.eql('2.0');
});
it('Constructor with no auth credentials', () => {
const { username, password, ...options } = getOptions();
expect(options.username).to.not.eql(username);
expect(options.password).to.not.eql(password);
const jira = new JiraApi(options);
expect(jira.baseOptions.auth).to.be.undefined;
});
it('Constructor with bearer credentials', () => {
const options = getOptions({
bearer: 'testBearer',
});
const jira = new JiraApi(options);
expect(jira.baseOptions.auth).to.eql({
user: '',
pass: '',
sendImmediately: true,
bearer: options.bearer,
});
});
it('Constructor with oauth credentials', () => {
const options = getOptions({
oauth: {
consumer_key: 'consumer',
consumer_secret: 'consumer_secret',
access_token: 'token',
access_token_secret: 'token_secret',
},
});
const jira = new JiraApi(options);
expect(jira.baseOptions.oauth).to.eql({
consumer_key: 'consumer',
consumer_secret: 'consumer_secret',
token: 'token',
token_secret: 'token_secret',
signature_method: 'RSA-SHA1',
});
});
it('Constructor with timeout', () => {
const jira = new JiraApi({
timeout: 2,
...getOptions(),
});
expect(jira.baseOptions.timeout).to.equal(2);
});
it('Constructor with strictSSL off', () => {
const jira = new JiraApi(
getOptions({
strictSSL: false,
}),
);
expect(jira.strictSSL).to.equal(false);
});
it('should allow the user to pass in a certificate authority', () => {
const jira = new JiraApi(
getOptions({
ca: 'fakestring',
}),
);
expect(jira.baseOptions.ca).to.equal('fakestring');
});
});
describe('makeRequestHeader Tests', () => {
it('makeRequestHeader functions properly in the average case', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeRequestHeader(jira.makeUri({
pathname: '/somePathName',
}))).to.eql({
json: true,
method: 'GET',
rejectUnauthorized: true,
uri: 'http://jira.somehost.com:8080/rest/api/2.0/somePathName',
});
});
it('makeRequestHeader functions properly with a different method', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeRequestHeader(jira.makeUri({
pathname: '/somePathName',
}), { method: 'POST' })).to.eql({
json: true,
method: 'POST',
rejectUnauthorized: true,
uri: 'http://jira.somehost.com:8080/rest/api/2.0/somePathName',
});
});
});
describe('makeUri', () => {
it('builds url with pathname and default host, protocol, port, and base api', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeUri({ pathname: '/somePathName' }))
.to.eql('http://jira.somehost.com:8080/rest/api/2.0/somePathName');
});
it('builds url with intermediatePath', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeUri({ pathname: '/somePathName', intermediatePath: 'intermediatePath' }))
.to.eql('http://jira.somehost.com:8080/intermediatePath/somePathName');
});
it('builds url with globally specified intermediatePath', () => {
const jira = new JiraApi(getOptions({
intermediatePath: 'intermediatePath',
}));
expect(jira.makeUri({ pathname: '/somePathName' }))
.to.eql('http://jira.somehost.com:8080/intermediatePath/somePathName');
});
it('builds url with query string parameters', () => {
const jira = new JiraApi(getOptions());
const url = jira.makeUri({
pathname: '/path',
query: {
fields: [
'one',
'two',
],
expand: 'three',
},
});
url.should.eql(
'http://jira.somehost.com:8080/rest/api/2.0/path?fields=one&fields=two&expand=three',
);
});
it('makeWebhookUri functions properly in the average case', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeWebhookUri({
pathname: '/somePathName',
}))
.to.eql('http://jira.somehost.com:8080/rest/webhooks/1.0/somePathName');
});
it('makeWebhookUri functions with intermediate path', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeWebhookUri({
pathname: '/somePathName',
intermediatePath: '/someIntermediatePath',
}))
.to.eql('http://jira.somehost.com:8080/someIntermediatePath/somePathName');
});
it('makeSprintQueryUri functions properly in the average case', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeSprintQueryUri({
pathname: '/somePathName',
}))
.to.eql('http://jira.somehost.com:8080/rest/greenhopper/1.0/somePathName');
});
it('makeSprintQueryUri functions properly in the average case', () => {
const jira = new JiraApi(getOptions());
expect(jira.makeSprintQueryUri({
pathname: '/somePathName',
intermediatePath: '/someIntermediatePath',
}))
.to.eql('http://jira.somehost.com:8080/someIntermediatePath/somePathName');
});
it('makeUri functions properly no port http', () => {
const { port, ...options } = getOptions();
expect(options.port).to.not.eql(port);
const jira = new JiraApi(options);
expect(jira.makeUri({
pathname: '/somePathName',
}))
.to.eql('http://jira.somehost.com/rest/api/2.0/somePathName');
});
it('makeUri functions properly no port https', () => {
const { port, ...options } = getOptions({ protocol: 'https' });
expect(options.port).to.not.eql(port);
const jira = new JiraApi(options);
expect(jira.makeUri({
pathname: '/somePathName',
}))
.to.eql('https://jira.somehost.com/rest/api/2.0/somePathName');
});
});
describe('doRequest Tests', () => {
it('doRequest functions properly in the average case', async () => {
// eslint-disable-next-line no-underscore-dangle
const revert = JiraApi.__set__('_request', (uri, options, callback) => {
callback(undefined, { body: 'Successful response!' });
});
const jira = new JiraApi(getOptions());
const response = await jira.doRequest({});
response.should.eql('Successful response!');
revert();
});
it('doRequest authenticates properly when specified', async () => {
async function dummyRequest(requestOptions) {
return requestOptions;
}
const username = 'someusername';
const password = 'somepassword';
const jira = new JiraApi(getOptions({
username,
password,
request: dummyRequest,
}));
const result = await jira.doRequest({});
expect(result.auth.user).to.eql(username);
expect(result.auth.pass).to.eql(password);
});
it('doRequest times out with specified option', async () => {
async function dummyRequest(requestOptions) {
return requestOptions;
}
const jira = new JiraApi({
timeout: 2,
...getOptions({ request: dummyRequest }),
});
const result = await jira.doRequest({});
expect(result.timeout).to.eql(2);
});
it('doRequest throws an error properly', async () => {
// eslint-disable-next-line no-underscore-dangle
const revert = JiraApi.__set__('_request', (uri, options, callback) => {
callback({
body: JSON.stringify({
errorMessages: ['some error to throw'],
}),
});
});
const jira = new JiraApi(getOptions());
await jira.doRequest({})
.should.eventually.be.rejectedWith('{"body":"{\\"errorMessages\\":[\\"some error to throw\\"]}"}');
revert();
});
it('doRequest throws a list of errors properly', async () => {
// eslint-disable-next-line no-underscore-dangle
const revert = JiraApi.__set__('_request', (uri, options, callback) => {
callback({
body:
JSON.stringify({ errorMessages: ['some error to throw', 'another error'] }),
});
});
const jira = new JiraApi(getOptions());
await jira.doRequest({})
.should.eventually.be.rejectedWith('{"body":"{\\"errorMessages\\":[\\"some error to throw\\",\\"another error\\"]}"}');
revert();
});
it('doRequest does not throw an error on empty response', async () => {
// eslint-disable-next-line no-underscore-dangle
const revert = JiraApi.__set__('_request', (uri, options, callback) => {
callback(undefined, {
body: undefined,
});
});
const jira = new JiraApi(getOptions());
const response = await jira.doRequest({});
expect(response).to.be.undefined;
revert();
});
it('doRequest throws an error when request failed', async () => {
// eslint-disable-next-line no-underscore-dangle
const revert = JiraApi.__set__('_request', (uri, options, callback) => {
callback('This is an error message', undefined);
});
const jira = new JiraApi(getOptions());
await jira.doRequest({})
.should.eventually.be.rejectedWith('This is an error message');
revert();
});
});
describe('Request Functions Tests', () => {
async function dummyURLCall(jiraApiMethodName, functionArguments, dummyRequestMethod, returnedValue = 'uri') {
let dummyRequest = dummyRequestMethod;
if (!dummyRequest) {
dummyRequest = async (requestOptions) => requestOptions;
}
const jira = new JiraApi(
getOptions({
request: dummyRequest,
}),
);
const resultObject = await jira[jiraApiMethodName].apply(jira, functionArguments);
// hack exposing the qs object as the query string in the URL so this is
// uniformly testable
if (resultObject.qs) {
const queryString = Object.keys(resultObject.qs).map((x) => `${x}=${resultObject.qs[x]}`)
.join('&');
return `${resultObject.uri}?${queryString}`;
}
return resultObject[returnedValue];
}
it('findIssue hits proper url', async () => {
const result = await dummyURLCall('findIssue', ['PK-100']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/PK-100?expand=&fields=*all&properties=*all&fieldsByKeys=false');
});
it('findIssue hits proper url with expansion', async () => {
const result = await dummyURLCall('findIssue', ['PK-100', 'transitions,changelog']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/PK-100?expand=transitions,changelog&fields=*all&properties=*all&fieldsByKeys=false');
});
it('findIssue hits proper url with fields', async () => {
const result = await dummyURLCall('findIssue', ['PK-100', null, 'transitions,changelog']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/PK-100?expand=&fields=transitions,changelog&properties=*all&fieldsByKeys=false');
});
it('findIssue hits proper url with properties', async () => {
const result = await dummyURLCall('findIssue', ['PK-100', null, null, 'transitions,changelog']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/PK-100?expand=&fields=*all&properties=transitions,changelog&fieldsByKeys=false');
});
it('findIssue hits proper url with fields and fieldsByKeys', async () => {
const result = await dummyURLCall('findIssue', ['PK-100', null, 'transitions,changelog', null, true]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/PK-100?expand=&fields=transitions,changelog&properties=*all&fieldsByKeys=true');
});
it('downloadAttachment hits proper url with attachment id and filename', async () => {
const result = await dummyURLCall('downloadAttachment', [{ id: '123456', filename: 'attachment.txt' }]);
result.should.eql('http://jira.somehost.com:8080/secure/attachment/123456/attachment.txt');
});
it('downloadAttachment hits proper url with attachment id and filename with special characters', async () => {
const result = await dummyURLCall('downloadAttachment', [{ id: '123456', filename: 'attachment-æøå.txt' }]);
result.should.eql('http://jira.somehost.com:8080/secure/attachment/123456/attachment-%C3%A6%C3%B8%C3%A5.txt');
});
it('deleteAttachment hits proper url', async () => {
const result = await dummyURLCall('deleteAttachment', ['123456']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/attachment/123456');
});
it('getUnresolvedIssueCount hits proper url', async () => {
async function dummyRequest(requestOptions) {
return { issuesUnresolvedCount: requestOptions };
}
const result = await dummyURLCall('getUnresolvedIssueCount', ['someVersion'], dummyRequest);
result.should
.eql('http://jira.somehost.com:8080/rest/api/2.0/version/someVersion/unresolvedIssueCount');
});
it('getProject hits proper url', async () => {
const result = await dummyURLCall('getProject', ['someProject']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/project/someProject');
});
it('createProject hits proper url', async () => {
const result = await dummyURLCall('createProject', ['dummyObject']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/project/');
});
it('findRapidView hits proper url', async () => {
async function dummyRequest(requestOptions) {
return {
views: [{
...requestOptions,
name: 'theNameToLookFor',
}],
};
}
const result = await dummyURLCall('findRapidView', ['theNameToLookFor'], dummyRequest);
result.should.eql('http://jira.somehost.com:8080/rest/greenhopper/1.0/rapidviews/list');
});
it('getLastSprintForRapidView hits proper url', async () => {
async function dummyRequest(requestOptions) {
return {
sprints: [requestOptions],
};
}
const result = await dummyURLCall(
'getLastSprintForRapidView',
['someRapidViewId'],
dummyRequest,
);
result.should.eql(
'http://jira.somehost.com:8080/rest/greenhopper/1.0/sprintquery/someRapidViewId',
);
});
it('getSprintIssues hits proper url', async () => {
const result = await dummyURLCall('getSprintIssues', ['someRapidView', 'someSprintId']);
result.should
.eql('http://jira.somehost.com:8080/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=someRapidView&sprintId=someSprintId');
});
it('listSprints hits proper url', async () => {
const result = await dummyURLCall('listSprints', ['someRapidViewId']);
result.should.eql(
'http://jira.somehost.com:8080/rest/greenhopper/1.0/sprintquery/someRapidViewId',
);
});
it('addIssueToSprint hits proper url', async () => {
const result = await dummyURLCall('addIssueToSprint', ['someIssueId', 'someSprintId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/sprint/someSprintId/issue');
});
it('issueLink hits proper url', async () => {
const result = await dummyURLCall('issueLink', ['somelink']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issueLink');
});
it('getRemoteLinks hits proper url', async () => {
const result = await dummyURLCall('getRemoteLinks', ['someIssueId']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueId/remotelink');
});
it('createRemoteLink hits proper url', async () => {
const result = await dummyURLCall('createRemoteLink', ['issueNumber', 'someRemoteLink']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/issueNumber/remotelink');
});
it('getVersion hits proper url', async () => {
const result = await dummyURLCall('getVersion', ['someVersion']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/version/someVersion');
});
it('getVersions hits proper url', async () => {
const result = await dummyURLCall('getVersions', ['someProject']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/project/someProject/versions');
});
it('getVersions hits proper url with query', async () => {
const result = await dummyURLCall('getVersions', ['someProject', { maxResults: 10 }]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/project/someProject/versions?maxResults=10');
});
it('createVersion hits proper url', async () => {
const result = await dummyURLCall('createVersion', ['someVersion']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/version');
});
it('updateVersion hits proper url', async () => {
const result = await dummyURLCall('updateVersion', [{ id: 'someVersionId' }]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/version/someVersionId');
});
it('deleteVersion hits proper url', async () => {
const result = await dummyURLCall('deleteVersion', [
'someVersionId',
'someFixVersionId',
'someAffectedVersionId',
]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/version/someVersionId?moveFixIssuesTo=someFixVersionId&moveAffectedIssuesTo=someAffectedVersionId');
});
it('seachJira hits proper url', async () => {
const result = await dummyURLCall('searchJira', ['someJQLhere', 'someOptionsObject']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/search');
});
it('createUser hits proper url', async () => {
const result = await dummyURLCall('createUser', [{
name: 'someUsername',
emailAddress: 'someEmail',
displayName: 'Some Name',
}]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/user');
});
it('searchUsers hits proper url', async () => {
const result = await dummyURLCall('searchUsers', [{
query: 'someOtherUserName',
username: 'someUserName',
}]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/user/search?username=someUserName&query=someOtherUserName&startAt=0&maxResults=50&includeActive=true&includeInactive=false');
});
it('getUsersInGroup hits proper url', async () => {
const result = await dummyURLCall('getUsersInGroup', ['someGroupName']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/group?groupname=someGroupName&expand=users[0:50]');
});
it('getMembersOfGroup hits proper url', async () => {
const result = await dummyURLCall('getMembersOfGroup', ['someGroupName']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/group/member?groupname=someGroupName&expand=users[0:50]&includeInactiveUsers=false');
});
it('getUsersIssues hits proper url', async () => {
const result = await dummyURLCall('getUsersIssues', ['someUsername', true]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/search');
});
it('getUser hits proper url', async () => {
const result = await dummyURLCall('getUser', ['some-account-Id', 'groups,applicationRoles']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/user?accountId=some-account-Id&expand=groups,applicationRoles');
});
it('getUsers hits proper url', async () => {
const result = await dummyURLCall('getUsers', [0, 50]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/users?startAt=0&maxResults=50');
});
it('addNewIssue hits proper url', async () => {
const result = await dummyURLCall('addNewIssue', ['someIssue']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue');
});
it('getUsersIssues hits proper url', async () => {
const result = await dummyURLCall('getUsersIssues', ['someUsername', 'true']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/search');
});
it('addWatcher hits proper url', async () => {
const result = await dummyURLCall('addWatcher', ['ZQ-9001']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/ZQ-9001/watchers');
});
it('addWatcher sends unquoted string in body', async () => {
const result = await dummyURLCall('addWatcher', ['ZQ-9001', 'John Smith'], null, 'body');
result.should.eql('John Smith');
});
it('deleteWatcher hits proper url', async() => {
const result = await dummyURLCall('deleteWatcher', ['ZQ-9001', 'some-account-Id']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/ZQ-9001/watchers?accountId=some-account-Id')
});
it('getIssueChangelog hits proper url', async () => {
const result = await dummyURLCall('getIssueChangelog', ['ZQ-9001']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/ZQ-9001/changelog?startAt=0&maxResults=50');
});
it('getIssueWatchers hits proper url', async () => {
const result = await dummyURLCall('getIssueWatchers', ['ZQ-9001']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/ZQ-9001/watchers');
});
it('updateAssignee hits proper url', async () => {
const result = await dummyURLCall('updateAssignee', ['ZQ-9001', 'Assignee']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/ZQ-9001/assignee');
});
it('updateAssigneeWithId hits proper url', async () => {
const result = await dummyURLCall('updateAssigneeWithId', ['ZQ-9001', 'Assignee']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/ZQ-9001/assignee');
});
it('deleteIssue hits proper url', async () => {
const result = await dummyURLCall('deleteIssue', ['FU-69']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/FU-69');
});
it('updateIssue hits proper url', async () => {
const result = await dummyURLCall('updateIssue', ['MI-6', 'someInfo']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/MI-6');
});
it('properly creates query params for updateIssue', async () => {
const result = await dummyURLCall('updateIssue', ['MI-6', 'someInfo', { notifyUsers: true }]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/MI-6?notifyUsers=true');
});
it('listComponents hits proper url', async () => {
const result = await dummyURLCall('listComponents', ['ProjectName']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/project/ProjectName/components');
});
it('addNewComponent hits proper url', async () => {
const result = await dummyURLCall('addNewComponent', ['someComponent']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/component');
});
it('updateComponent hits proper url', async () => {
const result = await dummyURLCall('updateComponent', ['someComponentNumber', 'someComponent']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/component/someComponentNumber');
});
it('deleteComponent hits proper url', async () => {
const result = await dummyURLCall('deleteComponent', ['someComponentNumber']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/component/someComponentNumber');
});
it('deleteComponent hits proper url', async () => {
const result = await dummyURLCall('deleteComponent', ['someComponentNumber', 'someComponentName']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/component/someComponentNumber?moveIssuesTo=someComponentName');
});
it('relatedIssueCounts hits proper url', async () => {
const result = await dummyURLCall('relatedIssueCounts', ['someComponentNumber', 'someComponentName']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/component/someComponentNumber/relatedIssueCounts');
});
// Field APIs Suite Tests
describe('Field APIs Suite Tests', () => {
it('createCustomField hits proper url', async () => {
const result = await dummyURLCall('createCustomField', ['someField']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field');
});
it('listFields hits proper url', async () => {
const result = await dummyURLCall('listFields', []);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field');
});
});
// Field Option APIs Suite Tests
describe('Field Option APIs Suite Tests', () => {
it('createFieldOption hits proper url', async () => {
const result = await dummyURLCall('createFieldOption', ['someFieldKey', 'someOption']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field/someFieldKey/option');
});
it('listFieldOptions hits proper url', async () => {
const result = await dummyURLCall('listFieldOptions', ['someFieldKey']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field/someFieldKey/option');
});
it('upsertFieldOption hits proper url', async () => {
const result = await dummyURLCall('upsertFieldOption', ['someFieldKey', 'someOptionId', 'someOption']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field/someFieldKey/option/someOptionId');
});
it('getFieldOption hits proper url', async () => {
const result = await dummyURLCall('getFieldOption', ['someFieldKey', 'someOptionId']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field/someFieldKey/option/someOptionId');
});
it('deleteFieldOption hits proper url', async () => {
const result = await dummyURLCall('deleteFieldOption', ['someFieldKey', 'someOptionId']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field/someFieldKey/option/someOptionId');
});
});
it('getIssueProperty hits proper url with expansion', async () => {
const result = await dummyURLCall('getIssueProperty', ['PK-100', 'somePropertyKey']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/PK-100/properties/somePropertyKey');
});
it('listPriorities hits proper url', async () => {
const result = await dummyURLCall('listPriorities', []);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/priority');
});
it('listTransitions hits proper url', async () => {
const result = await dummyURLCall('listTransitions', ['someIssueNumber']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/transitions?expand=transitions.fields');
});
it('transitionIssue hits proper url', async () => {
const result = await dummyURLCall('transitionIssue', [
'someIssueNumber',
'someTransitionObject',
]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/transitions');
});
it('listProjects hits proper url', async () => {
const result = await dummyURLCall('listProjects', []);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/project');
});
it('addComment hits proper url', async () => {
const result = await dummyURLCall('addComment', ['someIssueNumber', 'someComment']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/comment');
});
it('addCommentAdvanced hits proper url', async () => {
const result = await dummyURLCall('addCommentAdvanced', ['someIssueNumber', 'someComment']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/comment');
});
it('updateComment hits proper url', async () => {
const result = await dummyURLCall('updateComment', ['someIssueNumber', 'someCommentNumber', 'someComment']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/comment/someCommentNumber');
});
it('getComments hits proper url', async () => {
const result = await dummyURLCall('getComments', ['someIssueNumber']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/comment');
});
it('getComment hits proper url', async () => {
const result = await dummyURLCall('getComment', ['someIssueNumber', 'someCommentNumber']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/comment/someCommentNumber');
});
it('deleteComment hits proper url', async () => {
const result = await dummyURLCall('deleteComment', ['someIssueNumber', 'someCommentNumber']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/comment/someCommentNumber');
});
it('addWorklog hits proper url', async () => {
const result = await dummyURLCall('addWorklog', [
'someIssueNumber',
'someWorkLog',
'someNewEstimate',
]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/worklog?adjustEstimate=new&newEstimate=someNewEstimate');
});
it('addWorklog hits proper url with adjustEstimate=leave', async () => {
const result = await dummyURLCall('addWorklog', [
'someIssueNumber',
'someWorkLog',
'',
{ adjustEstimate: 'leave' },
]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/worklog?adjustEstimate=leave');
});
it('deleteWorklog hits proper url', async () => {
const result = await dummyURLCall('deleteWorklog', ['someIssueNumber', 'someWorklogId']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/worklog/someWorklogId');
});
it('updateWorklog hits proper url', async () => {
const result = await dummyURLCall('updateWorklog', ['someIssueNumber', 'someWorklogId']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/worklog/someWorklogId');
});
it('deleteIssueLink hits proper url', async () => {
const result = await dummyURLCall('deleteIssueLink', ['someLinkId']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issueLink/someLinkId');
});
it('getWorklogs hits proper url', async () => {
const result = await dummyURLCall('getWorklogs');
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/worklog/list?expand=');
});
it('getIssueWorklogs hits proper url', async () => {
const result = await dummyURLCall('getIssueWorklogs', ['someIssueNumber']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueNumber/worklog?startAt=0&maxResults=1000');
});
it('listIssueTypes hits proper url', async () => {
const result = await dummyURLCall('listIssueTypes', []);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issuetype');
});
it('listIssueLinkTypes hits proper url', async () => {
const result = await dummyURLCall('listIssueLinkTypes', []);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issueLinkType');
});
it('registerWebhook hits proper url', async () => {
const result = await dummyURLCall('registerWebhook', ['someWebhook']);
result.should.eql('http://jira.somehost.com:8080/rest/webhooks/1.0/webhook');
});
it('listWebhooks hits proper url', async () => {
const result = await dummyURLCall('listWebhooks', []);
result.should.eql('http://jira.somehost.com:8080/rest/webhooks/1.0/webhook');
});
it('getWebhook hits proper url', async () => {
const result = await dummyURLCall('getWebhook', ['someWebhookId']);
result.should.eql('http://jira.somehost.com:8080/rest/webhooks/1.0/webhook/someWebhookId');
});
it('deleteWebhook hits proper url', async () => {
const result = await dummyURLCall('deleteWebhook', ['someWebhookId']);
result.should.eql('http://jira.somehost.com:8080/rest/webhooks/1.0/webhook/someWebhookId');
});
it('getCurrentUser hits proper url', async () => {
const result = await dummyURLCall('getCurrentUser', []);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/myself');
});
it('getBacklogForRapidView hits proper url', async () => {
const result = await dummyURLCall('getBacklogForRapidView', ['someRapidViewId']);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/xboard/plan/backlog/data?rapidViewId=someRapidViewId');
});
it('addAttachmentOnIssue hits proper url', async () => {
const result = await dummyURLCall('addAttachmentOnIssue', ['someIssueId', {}]);
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/issue/someIssueId/attachments');
});
it('addAttachmentOnIssue hits proper url', async () => {
const result = await dummyURLCall('listStatus');
result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/status');
});
// Field Option APIs Suite Tests
describe('Dev-Status APIs Suite Tests', () => {
it('getDevStatusSummary hits proper url', async () => {
const result = await dummyURLCall('getDevStatusSummary', ['someIssueId']);
result.should.eql('http://jira.somehost.com:8080/rest/dev-status/latest/issue/summary?issueId=someIssueId');
});
it('getDevStatusDetail hits proper url - repo', async () => {
const result = await dummyURLCall('getDevStatusDetail', ['someIssueId', 'someApplicationType', 'repository']);
result.should.eql('http://jira.somehost.com:8080/rest/dev-status/latest/issue/detail?issueId=someIssueId&applicationType=someApplicationType&dataType=repository');
});
it('getDevStatusDetail hits proper url - pullrequest', async () => {
const result = await dummyURLCall('getDevStatusDetail', ['someIssueId', 'someApplicationType', 'pullrequest']);
result.should.eql('http://jira.somehost.com:8080/rest/dev-status/latest/issue/detail?issueId=someIssueId&applicationType=someApplicationType&dataType=pullrequest');
});
});
// Agile APIs Suite Tests
describe('Agile APIs Suite Tests', () => {
it('getIssue hits proper url', async () => {
const result = await dummyURLCall('getIssue', ['someIssueId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/issue/someIssueId?fields=&expand=');
});
it('getIssueEstimationForBoard hits proper url', async () => {
const result = await dummyURLCall('getIssueEstimationForBoard', ['someIssueId', 'someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/issue/someIssueId/estimation?boardId=someBoardId');
});
it('estimateIssueForBoard hits proper url', async () => {
const result = await dummyURLCall('estimateIssueForBoard', ['someIssueId', 'someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/issue/someIssueId/estimation?boardId=someBoardId');
});
it('rankIssues hits proper url', async () => {
const result = await dummyURLCall('rankIssues');
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/issue/rank');
});
it('moveToBacklog hits proper url', async () => {
const result = await dummyURLCall('moveToBacklog');
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/backlog/issue');
});
it('getAllBoards hits proper url', async () => {
const result = await dummyURLCall('getAllBoards');
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board?startAt=0&maxResults=50&type=&name=');
});
it('getAllBoards hits proper url with project key provided', async () => {
const result = await dummyURLCall('getAllBoards', [0, 50, undefined, undefined, 'someProjectKey']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board?startAt=0&maxResults=50&type=&name=&projectKeyOrId=someProjectKey');
});
it('createBoard hits proper url', async () => {
const result = await dummyURLCall('createBoard');
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board');
});
it('getBoard hits proper url', async () => {
const result = await dummyURLCall('getBoard', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId');
});
it('deleteBoard hits proper url', async () => {
const result = await dummyURLCall('deleteBoard', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId');
});
it('getIssuesForBacklog hits proper url', async () => {
const result = await dummyURLCall('getIssuesForBacklog', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/backlog?startAt=0&maxResults=50&jql=&validateQuery=true&fields=');
});
it('getConfiguration hits proper url', async () => {
const result = await dummyURLCall('getConfiguration', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/configuration');
});
it('getIssuesForBoard hits proper url', async () => {
const result = await dummyURLCall('getIssuesForBoard', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/issue?startAt=0&maxResults=50&jql=&validateQuery=true&fields=');
});
it('getFilter hits proper url', async () => {
const result = await dummyURLCall('getFilter', ['someFilterId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/filter/someFilterId');
});
it('getEpics hits proper url', async () => {
const result = await dummyURLCall('getEpics', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/epic?startAt=0&maxResults=50&done=');
});
it('getBoardIssuesForEpic hits proper url', async () => {
const result = await dummyURLCall('getBoardIssuesForEpic', ['someBoardId', 'someEpicId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/epic/someEpicId/issue?startAt=0&maxResults=50&jql=&validateQuery=true&fields=');
});
it('getProjects hits proper url', async () => {
const result = await dummyURLCall('getProjects', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/project?startAt=0&maxResults=50');
});
it('getProjectsFull hits proper url', async () => {
const result = await dummyURLCall('getProjectsFull', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/project/full');
});
it('getBoardPropertiesKeys hits proper url', async () => {
const result = await dummyURLCall('getBoardPropertiesKeys', ['someBoardId']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/properties');
});
it('deleteBoardProperty hits proper url', async () => {
const result = await dummyURLCall('deleteBoardProperty', ['someBoardId', 'somePropertyKey']);
result.should.eql('http://jira.somehost.com:8080/rest/agile/1.0/board/someBoardId/properties/somePropertyKey');
});
it('setBoardProperty hits proper url', async () => {