1
1
const { PRIORITIES , LABELS , STATUS , ...PROJECT_CONFIG } = require ( '../../../../scripts/prioritization/project-config' ) ;
2
2
const {
3
- createMockPR,
4
- createMockGithub ,
3
+ createMockPR,
4
+ createMockGithubForPriority ,
5
5
OPTION_IDS
6
6
} = require ( './helpers/mock-data' ) ;
7
7
@@ -13,39 +13,58 @@ describe('Priority Assignment (R1, R3, R4)', () => {
13
13
let mockContext ;
14
14
15
15
beforeEach ( ( ) => {
16
- mockGithub = createMockGithub ( ) ;
17
16
jest . clearAllMocks ( ) ;
18
17
} ) ;
19
18
20
19
async function verifyProjectState ( expectedPriority , expectedStatus ) {
21
- const calls = mockGithub . graphql . mock . calls ;
22
-
23
- if ( ! expectedPriority ) {
24
- const priorityUpdateCall = calls . find ( call =>
25
- call [ 1 ] . input ?. fieldId === PROJECT_CONFIG . priorityFieldId
26
- ) ;
27
- expect ( priorityUpdateCall ) . toBeUndefined ( ) ;
28
- return ;
29
- }
30
-
31
- const priorityUpdateCall = calls . find ( call =>
32
- call [ 1 ] . input ?. fieldId === PROJECT_CONFIG . priorityFieldId
33
- ) ;
34
- const statusUpdateCall = calls . find ( call =>
35
- call [ 1 ] . input ?. fieldId === PROJECT_CONFIG . statusFieldId
36
- ) ;
37
-
38
- // Verify priority was set correctly
39
- expect ( priorityUpdateCall [ 1 ] . input . value . singleSelectOptionId )
40
- . toBe ( OPTION_IDS [ expectedPriority ] ) ;
41
-
42
- // Verify status was set to Ready
43
- expect ( statusUpdateCall [ 1 ] . input . value . singleSelectOptionId )
44
- . toBe ( OPTION_IDS [ expectedStatus ] ) ;
20
+ const calls = mockGithub . graphql . mock . calls ;
21
+
22
+ if ( ! expectedPriority ) {
23
+ const priorityUpdateCall = calls . find ( call =>
24
+ call [ 1 ] . input ?. fieldId === PROJECT_CONFIG . priorityFieldId
25
+ ) ;
26
+ expect ( priorityUpdateCall ) . toBeUndefined ( ) ;
27
+ return ;
28
+ }
29
+
30
+ const fetchItemResponse = await mockGithub . graphql . mock . results [ 1 ] . value ;
31
+ const existingItem = fetchItemResponse ?. node ?. projectItems ?. nodes ?. [ 0 ] ;
32
+
33
+ // Find priority update call
34
+ const priorityUpdateCall = calls . find ( call =>
35
+ call [ 1 ] . input ?. fieldId === PROJECT_CONFIG . priorityFieldId
36
+ ) ;
37
+
38
+ // Verify priority was set correctly
39
+ expect ( priorityUpdateCall [ 1 ] . input . value . singleSelectOptionId )
40
+ . toBe ( OPTION_IDS [ expectedPriority ] ) ;
41
+
42
+ // Check if item exists in project
43
+ if ( existingItem ) {
44
+ // For existing items, verify no status update was attempted
45
+ const statusUpdateCall = calls . find ( call =>
46
+ call [ 1 ] . input ?. fieldId === PROJECT_CONFIG . statusFieldId
47
+ ) ;
48
+ expect ( statusUpdateCall ) . toBeUndefined ( ) ;
49
+
50
+ const actualStatus = existingItem . fieldValues . nodes
51
+ . find ( node => node . field ?. name === 'Status' ) ?. name ;
52
+ expect ( actualStatus ) . toBe ( expectedStatus ) ;
53
+ } else {
54
+ // For new items, verify status was set to Ready
55
+ const statusUpdateCall = calls . find ( call =>
56
+ call [ 1 ] . input ?. fieldId === PROJECT_CONFIG . statusFieldId
57
+ ) ;
58
+ expect ( statusUpdateCall [ 1 ] . input . value . singleSelectOptionId )
59
+ . toBe ( OPTION_IDS [ STATUS . READY ] ) ;
60
+ }
45
61
}
46
62
63
+
47
64
describe ( 'R1 Priority Tests' , ( ) => {
48
65
test ( 'should assign R1 and Ready status to non-draft PR with contribution/core label' , async ( ) => {
66
+ mockGithub = createMockGithubForPriority ( ) ;
67
+
49
68
const pr = createMockPR ( {
50
69
draft : false ,
51
70
labels : [ LABELS . CORE ]
@@ -58,6 +77,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
58
77
} ) ;
59
78
60
79
test ( 'should assign R1 and Ready status to non-draft PR with contribution/core and needs-maintainer-review labels' , async ( ) => {
80
+ mockGithub = createMockGithubForPriority ( ) ;
81
+
61
82
const pr = createMockPR ( {
62
83
draft : false ,
63
84
labels : [ LABELS . CORE , LABELS . MAINTAINER_REVIEW ]
@@ -70,6 +91,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
70
91
} ) ;
71
92
72
93
test ( 'should not add draft PR with contribution/core label to project' , async ( ) => {
94
+ mockGithub = createMockGithubForPriority ( ) ;
95
+
73
96
const pr = createMockPR ( {
74
97
draft : true ,
75
98
labels : [ LABELS . CORE ]
@@ -80,10 +103,29 @@ describe('Priority Assignment (R1, R3, R4)', () => {
80
103
await assignPriority ( { github : mockGithub , context : mockContext } ) ;
81
104
await verifyProjectState ( null ) ;
82
105
} ) ;
106
+
107
+ test ( 'should retain existing status when updating priority to R1' , async ( ) => {
108
+ mockGithub = createMockGithubForPriority ( {
109
+ existingPriority : PRIORITIES . R3 ,
110
+ existingStatus : STATUS . IN_PROGRESS
111
+ } ) ;
112
+
113
+ const pr = createMockPR ( {
114
+ draft : false ,
115
+ labels : [ LABELS . CORE ]
116
+ } ) ;
117
+
118
+ mockContext = { payload : { pull_request : pr } } ;
119
+
120
+ await assignPriority ( { github : mockGithub , context : mockContext } ) ;
121
+ await verifyProjectState ( PRIORITIES . R1 , STATUS . IN_PROGRESS ) ;
122
+ } ) ;
83
123
} ) ;
84
124
85
125
describe ( 'R3 Priority Tests' , ( ) => {
86
126
test ( 'should assign R3 and Ready status to non-draft PR with needs-maintainer-review label' , async ( ) => {
127
+ mockGithub = createMockGithubForPriority ( ) ;
128
+
87
129
const pr = createMockPR ( {
88
130
draft : false ,
89
131
labels : [ LABELS . MAINTAINER_REVIEW ]
@@ -96,6 +138,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
96
138
} ) ;
97
139
98
140
test ( 'should not assign R3 to draft PR with needs-maintainer-review label' , async ( ) => {
141
+ mockGithub = createMockGithubForPriority ( ) ;
142
+
99
143
const pr = createMockPR ( {
100
144
draft : true ,
101
145
labels : [ LABELS . MAINTAINER_REVIEW ]
@@ -106,10 +150,29 @@ describe('Priority Assignment (R1, R3, R4)', () => {
106
150
await assignPriority ( { github : mockGithub , context : mockContext } ) ;
107
151
await verifyProjectState ( null ) ;
108
152
} ) ;
153
+
154
+ test ( 'should retain existing status when updating priority to R3' , async ( ) => {
155
+ mockGithub = createMockGithubForPriority ( {
156
+ existingPriority : PRIORITIES . R4 ,
157
+ existingStatus : STATUS . IN_PROGRESS
158
+ } ) ;
159
+
160
+ const pr = createMockPR ( {
161
+ draft : false ,
162
+ labels : [ LABELS . MAINTAINER_REVIEW ]
163
+ } ) ;
164
+
165
+ mockContext = { payload : { pull_request : pr } } ;
166
+
167
+ await assignPriority ( { github : mockGithub , context : mockContext } ) ;
168
+ await verifyProjectState ( PRIORITIES . R3 , STATUS . IN_PROGRESS ) ;
169
+ } ) ;
109
170
} ) ;
110
171
111
172
describe ( 'R4 Priority Tests' , ( ) => {
112
173
test ( 'should assign R4 and Ready status to PR with pr/reviewer-clarification-requested and needs-community-review labels' , async ( ) => {
174
+ mockGithub = createMockGithubForPriority ( ) ;
175
+
113
176
const pr = createMockPR ( {
114
177
draft : true ,
115
178
labels : [
@@ -125,6 +188,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
125
188
} ) ;
126
189
127
190
test ( 'should assign R4 and Ready status to PR with pr-linter/exemption-requested and needs-community-review labels' , async ( ) => {
191
+ mockGithub = createMockGithubForPriority ( ) ;
192
+
128
193
const pr = createMockPR ( {
129
194
draft : true ,
130
195
labels : [
@@ -140,6 +205,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
140
205
} ) ;
141
206
142
207
test ( 'should assign R4 and Ready status to PR with pr/reviewer-clarification-requested and needs-maintainer-review labels' , async ( ) => {
208
+ mockGithub = createMockGithubForPriority ( ) ;
209
+
143
210
const pr = createMockPR ( {
144
211
draft : true ,
145
212
labels : [
@@ -155,6 +222,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
155
222
} ) ;
156
223
157
224
test ( 'should assign R4 and Ready status to PR with pr-linter/exemption-requested and needs-maintainer-review labels' , async ( ) => {
225
+ mockGithub = createMockGithubForPriority ( ) ;
226
+
158
227
const pr = createMockPR ( {
159
228
labels : [
160
229
LABELS . EXEMPTION_REQUESTED ,
@@ -169,6 +238,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
169
238
} ) ;
170
239
171
240
test ( 'should assign R4 and Ready status to PR with pr/reviewer-clarification-requested label and no review labels' , async ( ) => {
241
+ mockGithub = createMockGithubForPriority ( ) ;
242
+
172
243
const pr = createMockPR ( {
173
244
labels : [ LABELS . CLARIFICATION_REQUESTED ]
174
245
} ) ;
@@ -180,6 +251,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
180
251
} ) ;
181
252
182
253
test ( 'should assign R4 and Ready status to PR with pr-linter/exemption-requested label and no review labels' , async ( ) => {
254
+ mockGithub = createMockGithubForPriority ( ) ;
255
+
183
256
const pr = createMockPR ( {
184
257
draft : true ,
185
258
labels : [ LABELS . EXEMPTION_REQUESTED ]
@@ -190,10 +263,31 @@ describe('Priority Assignment (R1, R3, R4)', () => {
190
263
await assignPriority ( { github : mockGithub , context : mockContext } ) ;
191
264
await verifyProjectState ( PRIORITIES . R4 , STATUS . READY ) ;
192
265
} ) ;
266
+
267
+ test ( 'should retain existing status when updating priority to R4' , async ( ) => {
268
+ mockGithub = createMockGithubForPriority ( {
269
+ existingPriority : PRIORITIES . R5 ,
270
+ existingStatus : STATUS . PAUSED
271
+ } ) ;
272
+
273
+ const pr = createMockPR ( {
274
+ labels : [
275
+ LABELS . CLARIFICATION_REQUESTED ,
276
+ LABELS . COMMUNITY_REVIEW
277
+ ]
278
+ } ) ;
279
+
280
+ mockContext = { payload : { pull_request : pr } } ;
281
+
282
+ await assignPriority ( { github : mockGithub , context : mockContext } ) ;
283
+ await verifyProjectState ( PRIORITIES . R4 , STATUS . PAUSED ) ;
284
+ } ) ;
193
285
} ) ;
194
286
195
287
describe ( 'Priority Precedence Tests' , ( ) => {
196
288
test ( 'should assign R1 over R3 when PR has both contribution/core and needs-maintainer-review labels' , async ( ) => {
289
+ mockGithub = createMockGithubForPriority ( ) ;
290
+
197
291
const pr = createMockPR ( {
198
292
draft : false ,
199
293
labels : [
@@ -209,6 +303,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
209
303
} ) ;
210
304
211
305
test ( 'should assign R1 over R4 when PR has both contribution/core and pr/reviewer-clarification-requested labels' , async ( ) => {
306
+ mockGithub = createMockGithubForPriority ( ) ;
307
+
212
308
const pr = createMockPR ( {
213
309
draft : false ,
214
310
labels : [
@@ -223,6 +319,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
223
319
} ) ;
224
320
225
321
test ( 'should not assign any priority when no matching labels' , async ( ) => {
322
+ mockGithub = createMockGithubForPriority ( ) ;
323
+
226
324
const pr = createMockPR ( {
227
325
draft : false ,
228
326
labels : [ ]
0 commit comments