@@ -12,32 +12,30 @@ const postDeploymentReply = { id: 42 } as any
12
12
const postStatusReply = { } as any
13
13
14
14
describe ( 'create' , ( ) => {
15
- beforeEach ( ( ) => {
16
- process . env [ 'GITHUB_REPOSITORY' ] = 'owner/repo'
17
15
18
- let inputs = { } as any
19
- let inputSpy : jest . SpyInstance ;
20
16
21
- // @actions /core
22
- inputs = {
23
- 'token' : 'fake-token' ,
24
- 'type' : 'create' ,
25
- }
26
- inputSpy = jest . spyOn ( core , 'getInput' ) ;
27
- inputSpy . mockImplementation ( name => inputs [ name ] ) ;
17
+ beforeEach ( ( ) => {
18
+ process . env [ 'GITHUB_REPOSITORY' ] = 'owner/repo'
28
19
29
20
// @actions /github
30
21
Object . defineProperty ( github . context , 'actor' , { get : ( ) => 'fake-actor' } )
31
22
Object . defineProperty ( github . context , 'ref' , { get : ( ) => 'refs/heads/master' } )
32
23
} )
33
24
34
25
afterEach ( ( ) => {
35
- jest . resetAllMocks ( ) ;
36
- jest . clearAllMocks ( ) ;
26
+ jest . resetAllMocks ( )
27
+ jest . clearAllMocks ( )
37
28
} )
38
29
39
30
it ( '200' , async ( ) => {
40
31
// arrange
32
+ const inputs = {
33
+ 'token' : 'fake-token' ,
34
+ 'type' : 'create' ,
35
+ } as any
36
+ const inputSpy = jest . spyOn ( core , 'getInput' )
37
+ inputSpy . mockImplementation ( name => inputs [ name ] )
38
+
41
39
const getListDeployments = nock ( 'https://api.github.com' )
42
40
. get ( '/repos/owner/repo/deployments?ref=refs%2Fheads%2Fmaster&environment=master' )
43
41
. reply ( 200 , listDeploymentsReply )
@@ -50,18 +48,47 @@ describe('create', () => {
50
48
. post ( '/repos/owner/repo/deployments/42/statuses' )
51
49
. reply ( 200 , postStatusReply )
52
50
51
+ // act
52
+ await main . run ( )
53
+
54
+ // assert
55
+ getListDeployments . done ( )
56
+ postDeployment . done ( )
57
+ postStatus . done ( )
58
+ } )
59
+
60
+ it ( '400 when environment_url has no https:// prefix' , async ( ) => {
61
+ // arrange
62
+ const inputs = {
63
+ 'token' : 'fake-token' ,
64
+ 'type' : 'create' ,
65
+ 'environment_url' : 'test.app'
66
+ } as any
67
+ const inputSpy = jest . spyOn ( core , 'getInput' )
68
+ inputSpy . mockImplementation ( name => inputs [ name ] )
69
+
70
+ const setFailedSpy = jest . spyOn ( core , 'setFailed' )
71
+
72
+ const getListDeployments = nock ( 'https://api.github.com' )
73
+ . get ( '/repos/owner/repo/deployments?ref=refs%2Fheads%2Fmaster&environment=master' )
74
+ . reply ( 200 , listDeploymentsReply )
75
+
76
+ const postDeployment = nock ( 'https://api.github.com' )
77
+ . post ( '/repos/owner/repo/deployments' )
78
+ . reply ( 400 , { "resource" :"DeploymentStatus" , "code" :"custom" , "field" :"environment_url" , "message" :"environment_url must use http(s) scheme" } )
79
+
53
80
// act
54
81
try {
55
82
await main . run ( )
83
+ expect ( 'this should not be reached' ) . toEqual ( '' )
56
84
} catch ( error ) {
57
- console . error ( JSON . stringify ( error . toString ( ) , null , 2 ) )
58
- console . error ( JSON . stringify ( error . stack , null , 2 ) )
85
+ expect ( error . message ) . toEqual ( "{\"resource\":\"DeploymentStatus\",\"code\":\"custom\",\"field\":\"environment_url\",\"message\":\"environment_url must use http(s) scheme\"}" )
59
86
}
60
87
61
88
// assert
62
89
getListDeployments . done ( )
63
90
postDeployment . done ( )
64
- postStatus . done ( )
91
+ expect ( setFailedSpy . mock . calls ) . toHaveLength ( 1 )
65
92
} )
66
93
} )
67
94
@@ -70,24 +97,24 @@ describe('finish', () => {
70
97
process . env [ 'GITHUB_REPOSITORY' ] = 'owner/repo'
71
98
72
99
let inputs = { } as any
73
- let inputSpy : jest . SpyInstance ;
100
+ let inputSpy : jest . SpyInstance
74
101
75
102
// @actions /core
76
103
inputs = {
77
104
'token' : 'fake-token' ,
78
105
'type' : 'finish' ,
79
106
}
80
- inputSpy = jest . spyOn ( core , 'getInput' ) ;
81
- inputSpy . mockImplementation ( name => inputs [ name ] ) ;
107
+ inputSpy = jest . spyOn ( core , 'getInput' )
108
+ inputSpy . mockImplementation ( name => inputs [ name ] )
82
109
83
110
// @actions /github
84
111
Object . defineProperty ( github . context , 'actor' , { get : ( ) => 'fake-actor' } )
85
112
Object . defineProperty ( github . context , 'ref' , { get : ( ) => 'refs/heads/master' } )
86
113
} )
87
114
88
115
afterEach ( ( ) => {
89
- jest . resetAllMocks ( ) ;
90
- jest . clearAllMocks ( ) ;
116
+ jest . resetAllMocks ( )
117
+ jest . clearAllMocks ( )
91
118
} )
92
119
93
120
it ( '200' , async ( ) => {
@@ -97,12 +124,7 @@ describe('finish', () => {
97
124
. reply ( 200 , postStatusReply )
98
125
99
126
// act
100
- try {
101
- await main . run ( )
102
- } catch ( error ) {
103
- console . error ( JSON . stringify ( error . toString ( ) , null , 2 ) )
104
- console . error ( JSON . stringify ( error . stack , null , 2 ) )
105
- }
127
+ await main . run ( )
106
128
107
129
// assert
108
130
postDeploymentStatus . done ( )
@@ -114,25 +136,25 @@ describe('delete-all', () => {
114
136
process . env [ 'GITHUB_REPOSITORY' ] = 'owner/repo'
115
137
116
138
let inputs = { } as any
117
- let inputSpy : jest . SpyInstance ;
139
+ let inputSpy : jest . SpyInstance
118
140
119
141
// @actions /core
120
142
inputs = {
121
143
'token' : 'fake-token' ,
122
144
'type' : 'delete-all' ,
123
145
'environment' : 'staging'
124
146
}
125
- inputSpy = jest . spyOn ( core , 'getInput' ) ;
126
- inputSpy . mockImplementation ( name => inputs [ name ] ) ;
147
+ inputSpy = jest . spyOn ( core , 'getInput' )
148
+ inputSpy . mockImplementation ( name => inputs [ name ] )
127
149
128
150
// @actions /github
129
151
Object . defineProperty ( github . context , 'actor' , { get : ( ) => 'fake-actor' } )
130
152
Object . defineProperty ( github . context , 'ref' , { get : ( ) => 'refs/heads/master' } )
131
153
} )
132
154
133
155
afterEach ( ( ) => {
134
- jest . resetAllMocks ( ) ;
135
- jest . clearAllMocks ( ) ;
156
+ jest . resetAllMocks ( )
157
+ jest . clearAllMocks ( )
136
158
} )
137
159
138
160
it ( '200' , async ( ) => {
@@ -150,12 +172,7 @@ describe('delete-all', () => {
150
172
. reply ( 200 )
151
173
152
174
// act
153
- try {
154
- await main . run ( )
155
- } catch ( error ) {
156
- console . error ( JSON . stringify ( error . toString ( ) , null , 2 ) )
157
- console . error ( JSON . stringify ( error . stack , null , 2 ) )
158
- }
175
+ await main . run ( )
159
176
160
177
// assert
161
178
getListDeployments . done ( )
@@ -169,25 +186,25 @@ describe('delete', () => {
169
186
process . env [ 'GITHUB_REPOSITORY' ] = 'owner/repo'
170
187
171
188
let inputs = { } as any
172
- let inputSpy : jest . SpyInstance ;
189
+ let inputSpy : jest . SpyInstance
173
190
174
191
// @actions /core
175
192
inputs = {
176
193
'token' : 'fake-token' ,
177
194
'type' : 'delete' ,
178
195
'deployment_id' : '42'
179
196
}
180
- inputSpy = jest . spyOn ( core , 'getInput' ) ;
181
- inputSpy . mockImplementation ( name => inputs [ name ] ) ;
197
+ inputSpy = jest . spyOn ( core , 'getInput' )
198
+ inputSpy . mockImplementation ( name => inputs [ name ] )
182
199
183
200
// @actions /github
184
201
Object . defineProperty ( github . context , 'actor' , { get : ( ) => 'fake-actor' } )
185
202
Object . defineProperty ( github . context , 'ref' , { get : ( ) => 'refs/heads/master' } )
186
203
} )
187
204
188
205
afterEach ( ( ) => {
189
- jest . resetAllMocks ( ) ;
190
- jest . clearAllMocks ( ) ;
206
+ jest . resetAllMocks ( )
207
+ jest . clearAllMocks ( )
191
208
} )
192
209
193
210
it ( '200' , async ( ) => {
@@ -201,12 +218,7 @@ describe('delete', () => {
201
218
. reply ( 200 )
202
219
203
220
// act
204
- try {
205
- await main . run ( )
206
- } catch ( error ) {
207
- console . error ( JSON . stringify ( error . toString ( ) , null , 2 ) )
208
- console . error ( JSON . stringify ( error . stack , null , 2 ) )
209
- }
221
+ await main . run ( )
210
222
211
223
// assert
212
224
postStatus . done ( )
0 commit comments