@@ -14,7 +14,7 @@ import exp from 'constants'
1414
1515describe ( 'action' , ( ) => {
1616 beforeEach ( ( ) => {
17- jest . clearAllMocks ( )
17+ jest . restoreAllMocks ( )
1818 jest . spyOn ( core , 'debug' ) . mockReturnValue ( )
1919 jest . spyOn ( core , 'info' ) . mockReturnValue ( )
2020 jest . spyOn ( core , 'group' ) . mockImplementation ( async ( name , fn ) => {
@@ -125,7 +125,7 @@ describe('action', () => {
125125
126126 describe ( 'input branch same as current branch' , ( ) => {
127127 beforeEach ( ( ) => {
128- jest . spyOn ( core , 'getInput' ) . mockImplementationOnce ( ( name , option ) => {
128+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
129129 if ( name == 'branch-name' ) return 'main'
130130 return ''
131131 } )
@@ -140,7 +140,9 @@ describe('action', () => {
140140 await main . run ( )
141141
142142 expect ( switchBranchMock ) . not . toHaveBeenCalled ( )
143- expect ( setFailedMock ) . not . toHaveBeenCalled ( )
143+ expect ( setFailedMock ) . toHaveBeenCalledWith (
144+ 'Neither files nor tag input has been configured'
145+ )
144146 } )
145147
146148 it ( 'does not push branch' , async ( ) => {
@@ -156,13 +158,15 @@ describe('action', () => {
156158
157159 expect ( switchBranchMock ) . not . toHaveBeenCalled ( )
158160 expect ( pushBranchMock ) . not . toHaveBeenCalled ( )
159- expect ( setFailedMock ) . not . toHaveBeenCalled ( )
161+ expect ( setFailedMock ) . toHaveBeenCalledWith (
162+ 'Neither files nor tag input has been configured'
163+ )
160164 } )
161165 } )
162166
163167 describe ( 'input branch not the same as current branch' , ( ) => {
164168 beforeEach ( ( ) => {
165- jest . spyOn ( core , 'getInput' ) . mockImplementationOnce ( ( name , option ) => {
169+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
166170 if ( name == 'branch-name' ) return 'another-branch'
167171 return ''
168172 } )
@@ -195,7 +199,45 @@ describe('action', () => {
195199
196200 expect ( switchBranchMock ) . toHaveBeenCalled ( )
197201 expect ( pushBranchMock ) . toHaveBeenCalled ( )
198- expect ( setFailedMock ) . not . toHaveBeenCalled ( )
202+ expect ( setFailedMock ) . toHaveBeenCalledWith (
203+ 'Neither files nor tag input has been configured'
204+ )
205+ } )
206+ } )
207+
208+ describe ( 'input repository is given' , ( ) => {
209+ describe ( 'valid format' , ( ) => {
210+ beforeEach ( ( ) => {
211+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
212+ if ( name == 'repository' ) return 'the-user/the-repo'
213+ return ''
214+ } )
215+ } )
216+
217+ it ( 'succeed' , async ( ) => {
218+ const setFailedMock = jest . spyOn ( core , 'setFailed' ) . mockReturnValue ( )
219+ await main . run ( )
220+ expect ( setFailedMock ) . toHaveBeenCalledWith (
221+ 'Neither files nor tag input has been configured'
222+ )
223+ } )
224+ } )
225+
226+ describe ( 'invalid format' , ( ) => {
227+ beforeEach ( ( ) => {
228+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
229+ if ( name == 'repository' ) return 'the-user-the-repo'
230+ return ''
231+ } )
232+ } )
233+
234+ it ( 'fails' , async ( ) => {
235+ const setFailedMock = jest . spyOn ( core , 'setFailed' ) . mockReturnValue ( )
236+ await main . run ( )
237+ expect ( setFailedMock ) . toHaveBeenCalledWith (
238+ 'Input <repository> "the-user-the-repo" is invalid'
239+ )
240+ } )
199241 } )
200242 } )
201243
@@ -210,10 +252,11 @@ describe('action', () => {
210252
211253 describe ( 'exists in remote' , ( ) => {
212254 beforeEach ( ( ) => {
213- jest . spyOn ( core , 'getInput' ) . mockImplementationOnce ( ( name , option ) => {
255+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
214256 if ( name == 'branch-name' ) return 'existing-branch'
215257 return ''
216258 } )
259+ jest . spyOn ( core , 'getBooleanInput' ) . mockReturnValue ( true )
217260 } )
218261
219262 it ( 'succeed' , async ( ) => {
@@ -246,7 +289,7 @@ describe('action', () => {
246289
247290 describe ( 'does not exist in remote' , ( ) => {
248291 beforeEach ( ( ) => {
249- jest . spyOn ( core , 'getInput' ) . mockImplementationOnce ( ( name , option ) => {
292+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
250293 if ( name == 'branch-name' ) return 'new-branch'
251294 return ''
252295 } )
@@ -355,7 +398,7 @@ describe('action', () => {
355398 } )
356399
357400 it ( 'commit files and output commit sha' , async ( ) => {
358- jest . spyOn ( core , 'getInput' ) . mockImplementationOnce ( ( name , option ) => {
401+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
359402 if ( name == 'branch-name' ) return 'custom-branch'
360403 return ''
361404 } )
@@ -404,7 +447,7 @@ describe('action', () => {
404447 } )
405448
406449 it ( 'push tag only' , async ( ) => {
407- jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , option ) => {
450+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
408451 if ( name == 'branch-name' ) return 'tag-branch'
409452 if ( name == 'tag' ) return 'fake-tag'
410453 return ''
@@ -450,7 +493,7 @@ describe('action', () => {
450493 } )
451494
452495 it ( 'commit file and push tag' , async ( ) => {
453- jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , option ) => {
496+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
454497 if ( name == 'branch-name' ) return 'file-tag-branch'
455498 if ( name == 'tag' ) return 'fake-file-tag'
456499 return ''
@@ -507,7 +550,7 @@ describe('action', () => {
507550 } )
508551
509552 it ( 'commit file fails woukd skip push tag' , async ( ) => {
510- jest . spyOn ( core , 'getInput' ) . mockImplementationOnce ( ( name , option ) => {
553+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name , _option ) => {
511554 if ( name == 'branch-name' ) return 'file-fail-tag-branch'
512555 if ( name == 'tag' ) return 'unreachable-tag'
513556 return ''
0 commit comments