bug: Mock PR body in test

* Mock body to get consistent testing
* Fix lint warnings
This commit is contained in:
Thomas Ruggeri
2025-12-22 20:31:50 +00:00
parent 99c27add52
commit 33c7a0bfc8
4 changed files with 26 additions and 15 deletions

2
dist/index.js generated vendored
View File

@@ -10497,9 +10497,7 @@ const util = __importStar(__nccwpck_require__(9180));
async function run() {
const token = core.getInput('github-token');
if (!token) {
/* eslint-disable no-template-curly-in-string */
core.setFailed('github-token is not set! Please add \'github-token: "${{ secrets.GITHUB_TOKEN }}"\' to your workflow file.');
/* eslint-enable no-template-curly-in-string */
return;
}
try {

View File

@@ -1,4 +1,4 @@
/* eslint-disable no-console, @typescript-eslint/no-var-requires, no-unused-expressions */
import * as github from '@actions/github'
import { Context } from '@actions/github/lib/context'
import * as dotenv from 'dotenv'

View File

@@ -11,6 +11,19 @@ beforeEach(() => {
jest.spyOn(core, 'setFailed').mockImplementation(jest.fn())
jest.spyOn(core, 'startGroup').mockImplementation(jest.fn())
jest.spyOn(core, 'getBooleanInput').mockReturnValue(false)
jest.spyOn(util, 'getBody').mockReturnValue(`
Bumps [fake/package](https://github.com/) from 0.0.0 to 0.0.1.
<details>
<summary>Release notes</summary>
<blockquote>
<h2>0.0.1</h2>
<h2>Summary</h2>
<p>This is a fake description for a fake update</p>
<h2>What's Changed</h2>
* Nothing
</blockquote>
</details>
`)
})
test('it early exits with an error if github-token is not set', async () => {
@@ -22,10 +35,10 @@ test('it early exits with an error if github-token is not set', async () => {
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('github-token is not set!')
)
/* eslint-disable no-unused-expressions */
expect(dependabotCommits.getMessage).not.toHaveBeenCalled
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
/* eslint-enable no-unused-expressions */
})
test('it does nothing if the PR is not verified as from Dependabot', async () => {
@@ -40,9 +53,9 @@ test('it does nothing if the PR is not verified as from Dependabot', async () =>
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('PR is not from Dependabot, nothing to do.')
)
/* eslint-disable no-unused-expressions */
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
/* eslint-enable no-unused-expressions */
})
test('it does nothing if there is no metadata in the commit', async () => {
@@ -57,9 +70,9 @@ test('it does nothing if there is no metadata in the commit', async () => {
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('PR does not contain metadata, nothing to do.')
)
/* eslint-disable no-unused-expressions */
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
/* eslint-enable no-unused-expressions */
})
test('it sets the updated dependency as an output for subsequent actions when given a commit message for application', async () => {
@@ -499,9 +512,9 @@ test('it sets the action to failed if there is an unexpected exception', async (
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('Something bad happened!')
)
/* eslint-disable no-unused-expressions */
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
/* eslint-enable no-unused-expressions */
})
test('it sets the action to failed if there is a request error', async () => {
@@ -525,7 +538,7 @@ test('it sets the action to failed if there is a request error', async () => {
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('(500) Something bad happened!')
)
/* eslint-disable no-unused-expressions */
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
/* eslint-enable no-unused-expressions */
})

View File

@@ -10,11 +10,11 @@ export async function run (): Promise<void> {
const token = core.getInput('github-token')
if (!token) {
/* eslint-disable no-template-curly-in-string */
core.setFailed(
'github-token is not set! Please add \'github-token: "${{ secrets.GITHUB_TOKEN }}"\' to your workflow file.'
)
/* eslint-enable no-template-curly-in-string */
return
}