@@ -10,7 +10,6 @@ test('that Configuration validates root node in yml', () => {
10
10
} )
11
11
12
12
// write test to test for bad yml
13
-
14
13
test ( 'that constructor loads settings correctly' , ( ) => {
15
14
let config = new Configuration ( `
16
15
mergeable:
@@ -33,6 +32,7 @@ test('that defaults load correctly when mergeable is null', () => {
33
32
expect ( mergeable . title ) . toBe ( Configuration . DEFAULTS . title )
34
33
expect ( mergeable . label ) . toBe ( Configuration . DEFAULTS . label )
35
34
expect ( mergeable . exclude ) . toBe ( undefined )
35
+ expect ( mergeable . stale ) . toBe ( Configuration . DEFAULTS . stale )
36
36
} )
37
37
38
38
test ( 'that defaults load correctly when mergeable has partial properties defined' , ( ) => {
@@ -48,29 +48,12 @@ test('that defaults load correctly when mergeable has partial properties defined
48
48
} )
49
49
50
50
test ( 'that instanceWithContext returns the right Configuration' , async ( ) => {
51
- let context = {
52
- repo : jest . fn ( ) . mockReturnValue ( {
53
- repo : '' ,
54
- owner : ''
55
- } ) ,
56
- payload : {
57
- pull_request : {
58
- number : 1
59
- }
60
- } ,
61
- github : {
62
- repos : {
63
- getContent : jest . fn ( ) . mockReturnValue (
64
- Promise . resolve ( { data : { content : Buffer . from ( `
65
- mergeable:
66
- approvals: 5
67
- label: 'label regex'
68
- title: 'title regex'
69
- ` ) . toString ( 'base64' ) } } )
70
- )
71
- }
72
- }
73
- }
51
+ let context = createMockGhConfig ( `
52
+ mergeable:
53
+ approvals: 5
54
+ label: 'label regex'
55
+ title: 'title regex'
56
+ ` )
74
57
75
58
Configuration . instanceWithContext ( context ) . then ( config => {
76
59
let mergeable = config . settings . mergeable
@@ -82,29 +65,12 @@ test('that instanceWithContext returns the right Configuration', async () => {
82
65
} )
83
66
84
67
test ( 'that instanceWithContext returns the right Configuration (pull_requrests)' , async ( ) => {
85
- let context = {
86
- repo : jest . fn ( ) . mockReturnValue ( {
87
- repo : '' ,
88
- owner : ''
89
- } ) ,
90
- payload : {
91
- pull_request : {
92
- number : 1
93
- }
94
- } ,
95
- github : {
96
- repos : {
97
- getContent : jest . fn ( ) . mockReturnValue (
98
- Promise . resolve ( { data : { content : Buffer . from ( `
99
- mergeable:
100
- pull_requests:
101
- label: 'label issue regex'
102
- title: 'title issue regex'
103
- ` ) . toString ( 'base64' ) } } )
104
- )
105
- }
106
- }
107
- }
68
+ let context = createMockGhConfig ( `
69
+ mergeable:
70
+ pull_requests:
71
+ label: 'label issue regex'
72
+ title: 'title issue regex'
73
+ ` )
108
74
109
75
await Configuration . instanceWithContext ( context ) . then ( config => {
110
76
let mergeable = config . settings . mergeable
@@ -117,29 +83,12 @@ test('that instanceWithContext returns the right Configuration (pull_requrests)'
117
83
} )
118
84
119
85
test ( 'that instanceWithContext returns the right Configuration (issues)' , async ( ) => {
120
- let context = {
121
- repo : jest . fn ( ) . mockReturnValue ( {
122
- repo : '' ,
123
- owner : ''
124
- } ) ,
125
- payload : {
126
- pull_request : {
127
- number : 1
128
- }
129
- } ,
130
- github : {
131
- repos : {
132
- getContent : jest . fn ( ) . mockReturnValue (
133
- Promise . resolve ( { data : { content : Buffer . from ( `
134
- mergeable:
135
- issues:
136
- label: 'label issue regex'
137
- title: 'title issue regex'
138
- ` ) . toString ( 'base64' ) } } )
139
- )
140
- }
141
- }
142
- }
86
+ let context = createMockGhConfig ( `
87
+ mergeable:
88
+ issues:
89
+ label: 'label issue regex'
90
+ title: 'title issue regex'
91
+ ` )
143
92
144
93
await Configuration . instanceWithContext ( context ) . then ( config => {
145
94
let mergeable = config . settings . mergeable
@@ -151,6 +100,58 @@ test('that instanceWithContext returns the right Configuration (issues)', async
151
100
expect ( context . github . repos . getContent . mock . calls . length ) . toBe ( 1 )
152
101
} )
153
102
103
+ test ( 'that instanceWithContext loads the configuration for stale correctly when specified for pull_requests and issues separately' , async ( ) => {
104
+ let context = createMockGhConfig ( `
105
+ mergeable:
106
+ pull_requests:
107
+ label: 'label issue regex'
108
+ title: 'title issue regex'
109
+ stale:
110
+ days: 20
111
+ ` )
112
+
113
+ await Configuration . instanceWithContext ( context ) . then ( config => {
114
+ let mergeable = config . settings . mergeable
115
+ expect ( mergeable . pull_requests . stale !== undefined ) . toBe ( true )
116
+ expect ( mergeable . pull_requests . stale . days ) . toBe ( 20 )
117
+ expect ( mergeable . pull_requests . stale . message ) . toBe ( Configuration . DEFAULTS . stale . message )
118
+ } )
119
+
120
+ context = createMockGhConfig ( `
121
+ mergeable:
122
+ issues:
123
+ stale:
124
+ days: 20
125
+ ` )
126
+
127
+ await Configuration . instanceWithContext ( context ) . then ( config => {
128
+ let mergeable = config . settings . mergeable
129
+ expect ( mergeable . issues . stale !== undefined ) . toBe ( true )
130
+ expect ( mergeable . issues . stale . days ) . toBe ( 20 )
131
+ expect ( mergeable . issues . stale . message ) . toBe ( Configuration . DEFAULTS . stale . message )
132
+ } )
133
+
134
+ context = createMockGhConfig ( `
135
+ mergeable:
136
+ issues:
137
+ stale:
138
+ days: 20
139
+ message: Issue test
140
+ pull_requests:
141
+ stale:
142
+ days: 20
143
+ message: PR test
144
+ ` )
145
+
146
+ await Configuration . instanceWithContext ( context ) . then ( config => {
147
+ let mergeable = config . settings . mergeable
148
+ expect ( mergeable . issues . stale !== undefined ) . toBe ( true )
149
+ expect ( mergeable . issues . stale . days ) . toBe ( 20 )
150
+ expect ( mergeable . issues . stale . message ) . toBe ( 'Issue test' )
151
+ expect ( mergeable . pull_requests . stale . message ) . toBe ( 'PR test' )
152
+ } )
153
+ } )
154
+
154
155
test ( 'that instanceWithContext still returns the Configuration when repo does not content mergeable.yml' , async ( ) => {
155
156
let context = {
156
157
repo : ( ) => {
@@ -187,6 +188,30 @@ test('that instanceWithContext still returns the Configuration when repo does no
187
188
expect ( context . github . repos . getContent . mock . calls . length ) . toBe ( 1 )
188
189
} )
189
190
191
+ // helper method to return mocked configiration.
192
+ const createMockGhConfig = ( json ) => {
193
+ return {
194
+ repo : jest . fn ( ) . mockReturnValue ( {
195
+ repo : '' ,
196
+ owner : ''
197
+ } ) ,
198
+ payload : {
199
+ pull_request : {
200
+ number : 1
201
+ }
202
+ } ,
203
+ github : {
204
+ repos : {
205
+ getContent : jest . fn ( ) . mockReturnValue (
206
+ Promise . resolve ( {
207
+ data : { content : Buffer . from ( json ) . toString ( 'base64' ) }
208
+ } )
209
+ )
210
+ }
211
+ }
212
+ }
213
+ }
214
+
190
215
// to mimic HttpError (https://github.com/octokit/rest.js/blob/fc8960ccf3415b5d77e50372d3bb873cfec80c55/lib/request/http-error.js)
191
216
class HttpError extends Error {
192
217
constructor ( message , code , status ) {
0 commit comments