@@ -10,18 +10,49 @@ vi.mock("execa", () => ({
10
10
} ,
11
11
} ) ) ;
12
12
13
+ const mockOutcomeLabel = {
14
+ color : "000000" ,
15
+ description : "def ghi" ,
16
+ name : "abc" ,
17
+ } ;
18
+
13
19
vi . mock ( "./outcomeLabels.js" , ( ) => ( {
14
- outcomeLabels : [
15
- {
16
- color : "000000" ,
17
- description : "def ghi" ,
18
- name : "abc" ,
19
- } ,
20
- ] ,
20
+ get outcomeLabels ( ) {
21
+ return [ mockOutcomeLabel ] ;
22
+ } ,
21
23
} ) ) ;
22
24
23
25
describe ( "migrateRepositoryLabels" , ( ) => {
24
- it ( "creates a setup label when it doesn't already exist" , async ( ) => {
26
+ it ( "creates a outcome label when labels stdout is returned" , async ( ) => {
27
+ mock$ . mockResolvedValue ( {
28
+ stdout : "" ,
29
+ } ) ;
30
+
31
+ await initializeRepositoryLabels ( ) ;
32
+
33
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
34
+ [
35
+ [
36
+ [
37
+ "gh label list --json color,description,name",
38
+ ],
39
+ ],
40
+ [
41
+ [
42
+ "gh label create ",
43
+ " --color ",
44
+ " --description ",
45
+ "",
46
+ ],
47
+ "abc",
48
+ "000000",
49
+ "def ghi",
50
+ ],
51
+ ]
52
+ ` ) ;
53
+ } ) ;
54
+
55
+ it ( "creates a outcome label when it doesn't already exist" , async ( ) => {
25
56
mock$ . mockResolvedValue ( {
26
57
stdout : JSON . stringify ( [
27
58
{
@@ -34,37 +65,148 @@ describe("migrateRepositoryLabels", () => {
34
65
35
66
await initializeRepositoryLabels ( ) ;
36
67
37
- expect ( mock$ ) . toHaveBeenCalledWith (
38
- [ "gh label create " , " --color " , " --description " , "" ] ,
39
- "abc" ,
40
- "000000" ,
41
- "def ghi" ,
42
- ) ;
68
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
69
+ [
70
+ [
71
+ [
72
+ "gh label list --json color,description,name",
73
+ ],
74
+ ],
75
+ [
76
+ [
77
+ "gh label create ",
78
+ " --color ",
79
+ " --description ",
80
+ "",
81
+ ],
82
+ "abc",
83
+ "000000",
84
+ "def ghi",
85
+ ],
86
+ ]
87
+ ` ) ;
88
+ } ) ;
89
+
90
+ it ( "doesn't edit a outcome label when it already exists with the same information" , async ( ) => {
91
+ mock$ . mockResolvedValue ( {
92
+ stdout : JSON . stringify ( [ mockOutcomeLabel ] ) ,
93
+ } ) ;
94
+
95
+ await initializeRepositoryLabels ( ) ;
96
+
97
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
98
+ [
99
+ [
100
+ [
101
+ "gh label list --json color,description,name",
102
+ ],
103
+ ],
104
+ ]
105
+ ` ) ;
43
106
} ) ;
44
107
45
- it ( "edits a setup label when it already exists" , async ( ) => {
108
+ it ( "edits a outcome label when it already exists with different color" , async ( ) => {
109
+ mock$ . mockResolvedValue ( {
110
+ stdout : JSON . stringify ( [
111
+ {
112
+ ...mockOutcomeLabel ,
113
+ color : "111111" ,
114
+ } ,
115
+ ] ) ,
116
+ } ) ;
117
+
118
+ await initializeRepositoryLabels ( ) ;
119
+
120
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
121
+ [
122
+ [
123
+ [
124
+ "gh label list --json color,description,name",
125
+ ],
126
+ ],
127
+ [
128
+ [
129
+ "gh label edit ",
130
+ " --color ",
131
+ " --description ",
132
+ " --name ",
133
+ "",
134
+ ],
135
+ "abc",
136
+ "000000",
137
+ "def ghi",
138
+ "abc",
139
+ ],
140
+ ]
141
+ ` ) ;
142
+ } ) ;
143
+
144
+ it ( "edits a outcome label when it already exists with different description" , async ( ) => {
145
+ mock$ . mockResolvedValue ( {
146
+ stdout : JSON . stringify ( [
147
+ {
148
+ ...mockOutcomeLabel ,
149
+ description : "updated" ,
150
+ } ,
151
+ ] ) ,
152
+ } ) ;
153
+
154
+ await initializeRepositoryLabels ( ) ;
155
+
156
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
157
+ [
158
+ [
159
+ [
160
+ "gh label list --json color,description,name",
161
+ ],
162
+ ],
163
+ [
164
+ [
165
+ "gh label edit ",
166
+ " --color ",
167
+ " --description ",
168
+ " --name ",
169
+ "",
170
+ ],
171
+ "abc",
172
+ "000000",
173
+ "def ghi",
174
+ "abc",
175
+ ],
176
+ ]
177
+ ` ) ;
178
+ } ) ;
179
+
180
+ it ( "deletes an existing non-outcome label when the equivalent outcome label already exists" , async ( ) => {
46
181
mock$ . mockResolvedValue ( {
47
182
stdout : JSON . stringify ( [
48
183
{
49
184
color : "000000" ,
50
185
description : "def ghi" ,
51
186
name : "abc" ,
52
187
} ,
188
+ {
189
+ color : "000000" ,
190
+ description : "def ghi" ,
191
+ name : "area: abc" ,
192
+ } ,
53
193
] ) ,
54
194
} ) ;
55
195
56
196
await initializeRepositoryLabels ( ) ;
57
197
58
- expect ( mock$ ) . toHaveBeenCalledWith (
59
- [ "gh label edit " , " --color " , " --description " , " --name " , "" ] ,
60
- "abc" ,
61
- "000000" ,
62
- "def ghi" ,
63
- "abc" ,
64
- ) ;
198
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
199
+ [
200
+ [
201
+ [
202
+ "gh label list --json color,description,name",
203
+ ],
204
+ ],
205
+ ]
206
+ ` ) ;
65
207
} ) ;
66
208
67
- it ( "deletes a pre-existing label when it isn't a setup label" , async ( ) => {
209
+ it ( "deletes a pre-existing label when it isn't a outcome label" , async ( ) => {
68
210
mock$ . mockResolvedValue ( {
69
211
stdout : JSON . stringify ( [
70
212
{
@@ -77,30 +219,60 @@ describe("migrateRepositoryLabels", () => {
77
219
78
220
await initializeRepositoryLabels ( ) ;
79
221
80
- expect ( mock$ ) . toHaveBeenCalledWith (
81
- [ "gh label delete " , " --yes" ] ,
82
- "unknown" ,
83
- ) ;
84
- expect ( mock$ ) . toHaveBeenCalledTimes ( 3 ) ;
222
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
223
+ [
224
+ [
225
+ [
226
+ "gh label list --json color,description,name",
227
+ ],
228
+ ],
229
+ [
230
+ [
231
+ "gh label create ",
232
+ " --color ",
233
+ " --description ",
234
+ "",
235
+ ],
236
+ "abc",
237
+ "000000",
238
+ "def ghi",
239
+ ],
240
+ ]
241
+ ` ) ;
85
242
} ) ;
86
243
87
- it ( "doesn't delete a pre-existing label when it isn't a setup label" , async ( ) => {
244
+ it ( "doesn't delete a pre-existing label when it isn't a outcome label" , async ( ) => {
88
245
mock$ . mockResolvedValue ( {
89
246
stdout : JSON . stringify ( [
90
247
{
91
248
color : "000000" ,
92
249
description : "def ghi" ,
93
- name : "abc " ,
250
+ name : "jkl " ,
94
251
} ,
95
252
] ) ,
96
253
} ) ;
97
254
98
255
await initializeRepositoryLabels ( ) ;
99
256
100
- expect ( mock$ ) . not . toHaveBeenCalledWith (
101
- [ "gh label delete " , " --yes" ] ,
102
- "abc" ,
103
- ) ;
104
- expect ( mock$ ) . toHaveBeenCalledTimes ( 2 ) ;
257
+ expect ( mock$ . mock . calls ) . toMatchInlineSnapshot ( `
258
+ [
259
+ [
260
+ [
261
+ "gh label list --json color,description,name",
262
+ ],
263
+ ],
264
+ [
265
+ [
266
+ "gh label create ",
267
+ " --color ",
268
+ " --description ",
269
+ "",
270
+ ],
271
+ "abc",
272
+ "000000",
273
+ "def ghi",
274
+ ],
275
+ ]
276
+ ` ) ;
105
277
} ) ;
106
278
} ) ;
0 commit comments