1
- import { Action } from "../src/Action" ;
2
- import { Artifact } from "../src/Artifact" ;
3
- import { Inputs } from "../src/Inputs" ;
4
- import { Releases } from "../src/Releases" ;
5
- import { ArtifactUploader } from "../src/ArtifactUploader" ;
6
- import { Outputs } from "../src/Outputs" ;
7
- import { ArtifactDestroyer } from "../src/ArtifactDestroyer" ;
8
- import { ActionSkipper } from "../src/ActionSkipper" ;
1
+ import { Action } from "../src/Action"
2
+ import { Artifact } from "../src/Artifact"
3
+ import { Inputs } from "../src/Inputs"
4
+ import { Releases } from "../src/Releases"
5
+ import { ArtifactUploader } from "../src/ArtifactUploader"
6
+ import { Outputs } from "../src/Outputs"
7
+ import { ArtifactDestroyer } from "../src/ArtifactDestroyer"
8
+ import { ActionSkipper } from "../src/ActionSkipper"
9
9
10
10
const applyReleaseDataMock = jest . fn ( )
11
11
const artifactDestroyMock = jest . fn ( )
@@ -18,30 +18,27 @@ const shouldSkipMock = jest.fn()
18
18
const updateMock = jest . fn ( )
19
19
const uploadMock = jest . fn ( )
20
20
21
- const artifacts = [
22
- new Artifact ( 'a/art1' ) ,
23
- new Artifact ( 'b/art2' )
24
- ]
21
+ const artifacts = [ new Artifact ( "a/art1" ) , new Artifact ( "b/art2" ) ]
25
22
26
- const createBody = ' createBody'
23
+ const createBody = " createBody"
27
24
const createDraft = true
28
- const createName = ' createName'
29
- const commit = ' commit'
30
- const discussionCategory = ' discussionCategory'
25
+ const createName = " createName"
26
+ const commit = " commit"
27
+ const discussionCategory = " discussionCategory"
31
28
const generateReleaseNotes = true
32
29
const id = 100
33
30
const createPrerelease = true
34
31
const releaseId = 101
35
32
const replacesArtifacts = true
36
- const tag = ' tag'
37
- const token = ' token'
38
- const updateBody = ' updateBody'
33
+ const tag = " tag"
34
+ const token = " token"
35
+ const updateBody = " updateBody"
39
36
const updateDraft = false
40
- const updateName = ' updateName'
37
+ const updateName = " updateName"
41
38
const updatePrerelease = false
42
39
const updateOnlyUnreleased = false
43
- const url = ' http://api.example.com'
44
- const makeLatest = ' legacy'
40
+ const url = " http://api.example.com"
41
+ const makeLatest = " legacy"
45
42
46
43
describe ( "Action" , ( ) => {
47
44
beforeEach ( ( ) => {
@@ -53,27 +50,29 @@ describe("Action", () => {
53
50
uploadMock . mockClear ( )
54
51
} )
55
52
56
- it ( ' creates release but does not upload if no artifact' , async ( ) => {
53
+ it ( " creates release but does not upload if no artifact" , async ( ) => {
57
54
const action = createAction ( false , false )
58
55
59
56
await action . perform ( )
60
57
61
- expect ( createMock ) . toBeCalledWith ( tag ,
58
+ expect ( createMock ) . toBeCalledWith (
59
+ tag ,
62
60
createBody ,
63
61
commit ,
64
62
discussionCategory ,
65
63
createDraft ,
66
64
generateReleaseNotes ,
67
65
makeLatest ,
68
66
createName ,
69
- createPrerelease )
67
+ createPrerelease
68
+ )
70
69
expect ( uploadMock ) . not . toBeCalled ( )
71
70
assertOutputApplied ( )
72
71
} )
73
72
74
- it ( ' creates release if no release exists to update' , async ( ) => {
73
+ it ( " creates release if no release exists to update" , async ( ) => {
75
74
const action = createAction ( true , true )
76
- const error = { status : 404 }
75
+ const error = { status : 404 }
77
76
getMock . mockRejectedValue ( error )
78
77
79
78
await action . perform ( )
@@ -87,19 +86,18 @@ describe("Action", () => {
87
86
generateReleaseNotes ,
88
87
makeLatest ,
89
88
createName ,
90
- createPrerelease )
89
+ createPrerelease
90
+ )
91
91
expect ( uploadMock ) . toBeCalledWith ( artifacts , releaseId , url )
92
92
assertOutputApplied ( )
93
93
} )
94
94
95
- it ( ' creates release if no draft releases' , async ( ) => {
95
+ it ( " creates release if no draft releases" , async ( ) => {
96
96
const action = createAction ( true , true )
97
- const error = { status : 404 }
97
+ const error = { status : 404 }
98
98
getMock . mockRejectedValue ( error )
99
99
listMock . mockResolvedValue ( {
100
- data : [
101
- { id : id , draft : false , tag_name : tag }
102
- ]
100
+ data : [ { id : id , draft : false , tag_name : tag } ] ,
103
101
} )
104
102
105
103
await action . perform ( )
@@ -117,10 +115,9 @@ describe("Action", () => {
117
115
)
118
116
expect ( uploadMock ) . toBeCalledWith ( artifacts , releaseId , url )
119
117
assertOutputApplied ( )
120
-
121
118
} )
122
119
123
- it ( ' creates release then uploads artifact' , async ( ) => {
120
+ it ( " creates release then uploads artifact" , async ( ) => {
124
121
const action = createAction ( false , true )
125
122
126
123
await action . perform ( )
@@ -140,7 +137,7 @@ describe("Action", () => {
140
137
assertOutputApplied ( )
141
138
} )
142
139
143
- it ( ' removes all artifacts when artifact destroyer is enabled' , async ( ) => {
140
+ it ( " removes all artifacts when artifact destroyer is enabled" , async ( ) => {
144
141
const action = createAction ( false , true , true )
145
142
146
143
await action . perform ( )
@@ -149,7 +146,7 @@ describe("Action", () => {
149
146
assertOutputApplied ( )
150
147
} )
151
148
152
- it ( ' removes no artifacts when artifact destroyer is disabled' , async ( ) => {
149
+ it ( " removes no artifacts when artifact destroyer is disabled" , async ( ) => {
153
150
const action = createAction ( false , true )
154
151
155
152
await action . perform ( )
@@ -158,7 +155,7 @@ describe("Action", () => {
158
155
assertOutputApplied ( )
159
156
} )
160
157
161
- it ( ' skips action' , async ( ) => {
158
+ it ( " skips action" , async ( ) => {
162
159
const action = createAction ( false , false , false )
163
160
shouldSkipMock . mockResolvedValue ( true )
164
161
@@ -168,7 +165,7 @@ describe("Action", () => {
168
165
expect ( updateMock ) . not . toBeCalled ( )
169
166
} )
170
167
171
- it ( ' throws error when create fails' , async ( ) => {
168
+ it ( " throws error when create fails" , async ( ) => {
172
169
const action = createAction ( false , true )
173
170
createMock . mockRejectedValue ( "error" )
174
171
@@ -193,14 +190,14 @@ describe("Action", () => {
193
190
expect ( uploadMock ) . not . toBeCalled ( )
194
191
} )
195
192
196
- it ( ' throws error when get fails' , async ( ) => {
193
+ it ( " throws error when get fails" , async ( ) => {
197
194
const action = createAction ( true , true )
198
195
const error = {
199
196
errors : [
200
197
{
201
- code : ' already_exists'
202
- }
203
- ]
198
+ code : " already_exists" ,
199
+ } ,
200
+ ] ,
204
201
}
205
202
206
203
createMock . mockRejectedValue ( error )
@@ -215,19 +212,17 @@ describe("Action", () => {
215
212
expect ( getMock ) . toBeCalledWith ( tag )
216
213
expect ( updateMock ) . not . toBeCalled ( )
217
214
expect ( uploadMock ) . not . toBeCalled ( )
218
-
219
215
} )
220
216
221
- it ( 'throws error when list has no data' , async ( ) => {
222
-
217
+ it ( "throws error when list has no data" , async ( ) => {
223
218
const action = createAction ( true , true )
224
- getMock . mockRejectedValue ( { status : 404 } )
219
+ getMock . mockRejectedValue ( { status : 404 } )
225
220
const error = {
226
221
errors : [
227
222
{
228
- code : ' already_exists'
229
- }
230
- ]
223
+ code : " already_exists" ,
224
+ } ,
225
+ ] ,
231
226
}
232
227
233
228
createMock . mockRejectedValue ( error )
@@ -244,7 +239,7 @@ describe("Action", () => {
244
239
expect ( updateMock ) . not . toBeCalled ( )
245
240
} )
246
241
247
- it ( ' throws error when update fails' , async ( ) => {
242
+ it ( " throws error when update fails" , async ( ) => {
248
243
const action = createAction ( true , true )
249
244
250
245
updateMock . mockRejectedValue ( "error" )
@@ -270,9 +265,9 @@ describe("Action", () => {
270
265
expect ( uploadMock ) . not . toBeCalled ( )
271
266
} )
272
267
273
- it ( ' throws error when upload fails' , async ( ) => {
268
+ it ( " throws error when upload fails" , async ( ) => {
274
269
const action = createAction ( false , true )
275
- const expectedError = { status : 404 }
270
+ const expectedError = { status : 404 }
276
271
uploadMock . mockRejectedValue ( expectedError )
277
272
278
273
expect . hasAssertions ( )
@@ -296,15 +291,15 @@ describe("Action", () => {
296
291
expect ( uploadMock ) . toBeCalledWith ( artifacts , releaseId , url )
297
292
} )
298
293
299
- it ( ' updates draft release' , async ( ) => {
294
+ it ( " updates draft release" , async ( ) => {
300
295
const action = createAction ( true , true )
301
- const error = { status : 404 }
296
+ const error = { status : 404 }
302
297
getMock . mockRejectedValue ( error )
303
298
listMock . mockResolvedValue ( {
304
299
data : [
305
- { id : 123 , draft : false , tag_name : tag } ,
306
- { id : id , draft : true , tag_name : tag }
307
- ]
300
+ { id : 123 , draft : false , tag_name : tag } ,
301
+ { id : id , draft : true , tag_name : tag } ,
302
+ ] ,
308
303
} )
309
304
310
305
await action . perform ( )
@@ -324,7 +319,7 @@ describe("Action", () => {
324
319
assertOutputApplied ( )
325
320
} )
326
321
327
- it ( ' updates release but does not upload if no artifact' , async ( ) => {
322
+ it ( " updates release but does not upload if no artifact" , async ( ) => {
328
323
const action = createAction ( true , false )
329
324
330
325
await action . perform ( )
@@ -344,7 +339,7 @@ describe("Action", () => {
344
339
assertOutputApplied ( )
345
340
} )
346
341
347
- it ( ' updates release then uploads artifact' , async ( ) => {
342
+ it ( " updates release then uploads artifact" , async ( ) => {
348
343
const action = createAction ( true , true )
349
344
350
345
await action . perform ( )
@@ -365,12 +360,10 @@ describe("Action", () => {
365
360
} )
366
361
367
362
function assertOutputApplied ( ) {
368
- expect ( applyReleaseDataMock ) . toBeCalledWith ( { id : releaseId , upload_url : url } )
363
+ expect ( applyReleaseDataMock ) . toBeCalledWith ( { id : releaseId , upload_url : url } )
369
364
}
370
365
371
- function createAction ( allowUpdates : boolean ,
372
- hasArtifact : boolean ,
373
- removeArtifacts : boolean = false ) : Action {
366
+ function createAction ( allowUpdates : boolean , hasArtifact : boolean , removeArtifacts : boolean = false ) : Action {
374
367
let inputArtifact : Artifact [ ]
375
368
if ( hasArtifact ) {
376
369
inputArtifact = artifacts
@@ -385,30 +378,30 @@ describe("Action", () => {
385
378
listArtifactsForRelease : listArtifactsMock ,
386
379
listReleases : listMock ,
387
380
update : updateMock ,
388
- uploadArtifact : jest . fn ( )
381
+ uploadArtifact : jest . fn ( ) ,
389
382
}
390
383
} )
391
384
392
385
createMock . mockResolvedValue ( {
393
386
data : {
394
387
id : releaseId ,
395
- upload_url : url
396
- }
388
+ upload_url : url ,
389
+ } ,
397
390
} )
398
391
getMock . mockResolvedValue ( {
399
392
data : {
400
- id : id
401
- }
393
+ id : id ,
394
+ } ,
402
395
} )
403
396
listMock . mockResolvedValue ( {
404
- data : [ ]
397
+ data : [ ] ,
405
398
} )
406
399
shouldSkipMock . mockResolvedValue ( false )
407
400
updateMock . mockResolvedValue ( {
408
401
data : {
409
402
id : releaseId ,
410
- upload_url : url
411
- }
403
+ upload_url : url ,
404
+ } ,
412
405
} )
413
406
uploadMock . mockResolvedValue ( { } )
414
407
@@ -436,28 +429,28 @@ describe("Action", () => {
436
429
updatedReleaseBody : updateBody ,
437
430
updatedReleaseName : updateName ,
438
431
updatedPrerelease : updatePrerelease ,
439
- updateOnlyUnreleased : updateOnlyUnreleased
432
+ updateOnlyUnreleased : updateOnlyUnreleased ,
440
433
}
441
434
} )
442
435
const MockOutputs = jest . fn < Outputs , any > ( ( ) => {
443
436
return {
444
- applyReleaseData : applyReleaseDataMock
437
+ applyReleaseData : applyReleaseDataMock ,
445
438
}
446
439
} )
447
440
const MockUploader = jest . fn < ArtifactUploader , any > ( ( ) => {
448
441
return {
449
- uploadArtifacts : uploadMock
442
+ uploadArtifacts : uploadMock ,
450
443
}
451
444
} )
452
445
const MockArtifactDestroyer = jest . fn < ArtifactDestroyer , any > ( ( ) => {
453
446
return {
454
- destroyArtifacts : artifactDestroyMock
447
+ destroyArtifacts : artifactDestroyMock ,
455
448
}
456
449
} )
457
450
458
451
const MockActionSkipper = jest . fn < ActionSkipper , any > ( ( ) => {
459
452
return {
460
- shouldSkip : shouldSkipMock
453
+ shouldSkip : shouldSkipMock ,
461
454
}
462
455
} )
463
456
0 commit comments