Skip to content

Commit

Permalink
unit test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Sep 20, 2024
1 parent f04b10b commit 05a16b7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const saveStateMock = jest.spyOn(core, 'saveState')
const setFailedMock = jest.spyOn(core, 'setFailed')
const infoMock = jest.spyOn(core, 'info')
const debugMock = jest.spyOn(core, 'debug')
const validDeploymentOrderMock = jest.spyOn(
validDeploymentOrder,
'validDeploymentOrder'
)

const permissionsMsg =
'👋 __monalisa__, seems as if you have not admin/write permissions in this repo, permissions: read'
Expand Down Expand Up @@ -261,6 +265,16 @@ test('runs the action and fails due to invalid environment deployment order', as
return undefined
})

jest.spyOn(prechecks, 'prechecks').mockImplementation(() => {
return {
ref: 'test-ref',
status: true,
message: '✔️ PR is approved and all CI checks passed - OK',
noopMode: false,
sha: 'deadbeef'
}
})

expect(await run()).toBe('failure')
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.deploy')
expect(setOutputMock).toHaveBeenCalledWith('triggered', 'true')
Expand All @@ -272,6 +286,14 @@ test('runs the action and fails due to invalid environment deployment order', as
expect(saveStateMock).toHaveBeenCalledWith('comment_id', 123)
expect(saveStateMock).toHaveBeenCalledWith('ref', 'test-ref')
expect(setOutputMock).toHaveBeenCalledWith('type', 'deploy')

expect(validDeploymentOrderMock).toHaveBeenCalledWith(
expect.any(Object),
expect.any(Object),
['development', 'staging', 'production'],
'production',
'deadbeef'
)
})

test('runs the action and passes environment deployment order checks', async () => {
Expand Down Expand Up @@ -513,6 +535,7 @@ test('successfully runs the action in lock mode - details only - lock alias wcid
status: 'details-only'
}
})

github.context.payload.comment.body = '.wcid'
expect(await run()).toBe('safe-exit')
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.wcid')
Expand All @@ -526,6 +549,8 @@ test('successfully runs the action in lock mode - details only - lock alias wcid
expect(saveStateMock).toHaveBeenCalledWith('actionsToken', 'faketoken')
expect(saveStateMock).toHaveBeenCalledWith('comment_id', 123)
expect(saveStateMock).toHaveBeenCalledWith('bypass', 'true')

expect(validDeploymentOrderMock).not.toHaveBeenCalled()
})

test('successfully runs the action in lock mode - details only - lock alias wcid - and finds a global lock', async () => {
Expand Down

0 comments on commit 05a16b7

Please sign in to comment.