@@ -7,7 +7,7 @@ import {COLORS} from '../../src/functions/colors'
77
88const setOutputMock = jest . spyOn ( core , 'setOutput' )
99const infoMock = jest . spyOn ( core , 'info' )
10- const setFailedMock = jest . spyOn ( core , 'setFailed ' )
10+ const warningMock = jest . spyOn ( core , 'warning ' )
1111const debugMock = jest . spyOn ( core , 'debug' )
1212
1313const environment_targets = 'production,development,staging'
@@ -16,7 +16,7 @@ var context
1616var octokit
1717beforeEach ( ( ) => {
1818 jest . clearAllMocks ( )
19- jest . spyOn ( core , 'setFailed ' ) . mockImplementation ( ( ) => { } )
19+ jest . spyOn ( core , 'warning ' ) . mockImplementation ( ( ) => { } )
2020 jest . spyOn ( core , 'setOutput' ) . mockImplementation ( ( ) => { } )
2121 jest . spyOn ( core , 'info' ) . mockImplementation ( ( ) => { } )
2222 jest . spyOn ( core , 'debug' ) . mockImplementation ( ( ) => { } )
@@ -148,7 +148,25 @@ test('fails due to the context not being a PR merge', async () => {
148148 expect ( infoMock ) . toHaveBeenCalledWith (
149149 'event name: pull_request, action: opened, merged: false'
150150 )
151- expect ( setFailedMock ) . toHaveBeenCalledWith (
152- 'this workflow can only run in the context of a merged pull request'
151+ expect ( warningMock ) . toHaveBeenCalledWith (
152+ `this workflow can only run in the context of a ${ COLORS . highlight } merged${ COLORS . reset } pull request`
153+ )
154+ } )
155+
156+ test ( 'fails due to the context being a PR closed event but not a merge' , async ( ) => {
157+ context . payload . action = 'closed'
158+ context . payload . pull_request . merged = false
159+ context . payload . eventName = 'pull_request'
160+ expect (
161+ await unlockOnMerge ( octokit , context , environment_targets )
162+ ) . toStrictEqual ( false )
163+ expect ( warningMock ) . toHaveBeenCalledWith (
164+ `this workflow can only run in the context of a ${ COLORS . highlight } merged${ COLORS . reset } pull request`
165+ )
166+ expect ( infoMock ) . toHaveBeenCalledWith (
167+ 'event name: pull_request, action: closed, merged: false'
168+ )
169+ expect ( infoMock ) . toHaveBeenCalledWith (
170+ 'pull request was closed but not merged so this workflow will not run - OK'
153171 )
154172} )
0 commit comments