-
Notifications
You must be signed in to change notification settings - Fork 2
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 #93 from issue-ops/ncalteen/check
Update check logic
- Loading branch information
Showing
13 changed files
with
29,557 additions
and
1,384 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,102 @@ | ||
import { jest } from '@jest/globals' | ||
import * as github from '../__fixtures__/github.js' | ||
|
||
jest.unstable_mockModule('@actions/github', () => github) | ||
|
||
const messages = await import('../src/messages.js') | ||
|
||
const { getOctokit } = await import('@actions/github') | ||
const mocktokit = jest.mocked(getOctokit(process.env.GITHUB_TOKEN as string)) | ||
|
||
describe('messages', () => { | ||
beforeEach(() => { | ||
process.env.GITHUB_REPOSITORY = 'issue-ops/semver' | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('getCommentId()', () => { | ||
it('returns the ID of the existing comment', async () => { | ||
mocktokit.rest.issues.listComments.mockResolvedValue({ | ||
data: [ | ||
{ | ||
id: 1, | ||
body: 'test comment\n\n<!-- semver: workflow=workflow-name -->' | ||
} | ||
] | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any) | ||
|
||
const commentId = await messages.getCommentId() | ||
expect(commentId).toBe(1) | ||
}) | ||
|
||
it('returns undefined if no existing comment is present', async () => { | ||
mocktokit.rest.issues.listComments.mockResolvedValue({ | ||
data: [] | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any) | ||
|
||
const commentId = await messages.getCommentId() | ||
expect(commentId).toBe(undefined) | ||
}) | ||
}) | ||
|
||
describe('versionCheckComment()', () => { | ||
it('updates an existing comment (success)', async () => { | ||
mocktokit.rest.issues.listComments.mockResolvedValue({ | ||
data: [ | ||
{ | ||
id: 1, | ||
body: 'test comment\n\n<!-- semver: workflow=workflow-name -->' | ||
} | ||
] | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any) | ||
|
||
await messages.versionCheckComment(true, 'package.json') | ||
|
||
expect(mocktokit.rest.issues.updateComment).toHaveBeenCalled() | ||
}) | ||
|
||
it('updates an existing comment (failure)', async () => { | ||
mocktokit.rest.issues.listComments.mockResolvedValue({ | ||
data: [ | ||
{ | ||
id: 1, | ||
body: 'test comment\n\n<!-- semver: workflow=workflow-name -->' | ||
} | ||
] | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any) | ||
|
||
await messages.versionCheckComment(false, 'package.json') | ||
|
||
expect(mocktokit.rest.issues.updateComment).toHaveBeenCalled() | ||
}) | ||
|
||
it('creates a new comment (success)', async () => { | ||
mocktokit.rest.issues.listComments.mockResolvedValue({ | ||
data: [] | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any) | ||
|
||
await messages.versionCheckComment(true, 'package.json') | ||
|
||
expect(mocktokit.rest.issues.createComment).toHaveBeenCalled() | ||
}) | ||
|
||
it('creates a new comment (failure)', async () => { | ||
mocktokit.rest.issues.listComments.mockResolvedValue({ | ||
data: [] | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any) | ||
|
||
await messages.versionCheckComment(false, 'package.json') | ||
|
||
expect(mocktokit.rest.issues.createComment).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.