generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from github/v6-improvements
v6.0.0 Improvements
- Loading branch information
Showing
13 changed files
with
168 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as core from '@actions/core' | ||
import {validPermissions} from '../../src/functions/valid-permissions' | ||
|
||
const setOutputMock = jest.spyOn(core, 'setOutput') | ||
|
||
var octokit | ||
var context | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
jest.spyOn(core, 'setOutput').mockImplementation(() => {}) | ||
process.env.INPUT_PERMISSIONS = 'write,maintain,admin' | ||
|
||
context = { | ||
actor: 'monalisa' | ||
} | ||
|
||
octokit = { | ||
rest: { | ||
repos: { | ||
getCollaboratorPermissionLevel: jest.fn().mockReturnValueOnce({ | ||
status: 200, | ||
data: { | ||
permission: 'write' | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
test('determines that a user has valid permissions to invoke the Action', async () => { | ||
expect(await validPermissions(octokit, context)).toEqual(true) | ||
expect(setOutputMock).toHaveBeenCalledWith('actor', 'monalisa') | ||
}) | ||
|
||
test('determines that a user has does not valid permissions to invoke the Action', async () => { | ||
octokit.rest.repos.getCollaboratorPermissionLevel = jest | ||
.fn() | ||
.mockReturnValue({ | ||
status: 200, | ||
data: { | ||
permission: 'read' | ||
} | ||
}) | ||
|
||
expect(await validPermissions(octokit, context)).toEqual( | ||
'👋 __monalisa__, seems as if you have not write/maintain/admin permissions in this repo, permissions: read' | ||
) | ||
expect(setOutputMock).toHaveBeenCalledWith('actor', 'monalisa') | ||
}) | ||
|
||
test('fails to get actor permissions due to a bad status code', async () => { | ||
octokit.rest.repos.getCollaboratorPermissionLevel = jest | ||
.fn() | ||
.mockReturnValue({ | ||
status: 500 | ||
}) | ||
|
||
expect(await validPermissions(octokit, context)).toEqual( | ||
'Permission check returns non-200 status: 500' | ||
) | ||
expect(setOutputMock).toHaveBeenCalledWith('actor', 'monalisa') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.