1
+ import nock from "nock" ;
2
+
1
3
import jiraPrValidation from "./index" ;
2
4
3
5
declare const global : any ;
4
6
5
7
describe ( "jiraPrValidation()" , ( ) => {
8
+ const baseUrl = "https://some.jira.net" ;
9
+ const key = "PRJ" ;
10
+ const issue = "001" ;
11
+
6
12
beforeEach ( ( ) => {
13
+ global . danger = {
14
+ github : {
15
+ pr : {
16
+ title : `${ key } -${ issue } - My Test Title` ,
17
+ base : { ref : "pr-base" } ,
18
+ head : { ref : "pr-head" } ,
19
+ } ,
20
+ } ,
21
+ } ;
7
22
global . warn = jest . fn ( ) ;
8
23
global . message = jest . fn ( ) ;
9
24
global . fail = jest . fn ( ) ;
@@ -17,21 +32,47 @@ describe("jiraPrValidation()", () => {
17
32
global . markdown = undefined ;
18
33
} ) ;
19
34
20
- it ( "Checks for a that message has been called" , async ( ) => {
21
- global . danger = {
22
- github : {
23
- pr : {
24
- title : "My Test Title" ,
25
- base : { ref : "pr-base" } ,
26
- head : { ref : "pr-head" } ,
35
+ it ( "should not call fail message if Jira issue has no fixVersions" , async ( ) => {
36
+ nock ( baseUrl )
37
+ . get (
38
+ `/rest/api/3/issue/${ key } -${ issue } ?fields=issuetype,summary,fixVersions` ,
39
+ )
40
+ . reply ( 200 , {
41
+ fields : {
42
+ fixVersions : [ ] ,
43
+ issuetype : { name : "issue" } ,
44
+ summary : "title" ,
27
45
} ,
28
- } ,
29
- } ;
46
+ } ) ;
47
+
48
+ await jiraPrValidation ( baseUrl , "username" , "token" , key ) ;
49
+
50
+ expect ( global . message ) . toHaveBeenCalledWith (
51
+ "Jira issue: PRJ-001 | issue | title" ,
52
+ ) ;
53
+ expect ( global . fail ) . not . toHaveBeenCalled ( ) ;
54
+ } ) ;
55
+
56
+ it ( "should call fail message if Jira issue has fixVersions that doesn`t match base branch" , async ( ) => {
57
+ nock ( baseUrl )
58
+ . get (
59
+ `/rest/api/3/issue/${ key } -${ issue } ?fields=issuetype,summary,fixVersions` ,
60
+ )
61
+ . reply ( 200 , {
62
+ fields : {
63
+ fixVersions : [ { name : "v1" } ] ,
64
+ issuetype : { name : "issue" } ,
65
+ summary : "title" ,
66
+ } ,
67
+ } ) ;
30
68
31
- await jiraPrValidation ( " baseUrl" , "username" , "token" , "projectKey" ) ;
69
+ await jiraPrValidation ( baseUrl , "username" , "token" , key ) ;
32
70
33
- expect ( global . message ) . toHaveBeenCalledWith ( "PR Title: My Test Title" ) ;
34
- expect ( global . message ) . toHaveBeenCalledWith ( "PR Base: pr-base" ) ;
35
- expect ( global . message ) . toHaveBeenCalledWith ( "PR Head: pr-head" ) ;
71
+ expect ( global . message ) . toHaveBeenCalledWith (
72
+ "Jira issue: PRJ-001 | issue | title\nFix versions: v1" ,
73
+ ) ;
74
+ expect ( global . fail ) . toHaveBeenCalledWith (
75
+ "🚨 Base branch doesn't match Jira fixVersion" ,
76
+ ) ;
36
77
} ) ;
37
78
} ) ;
0 commit comments