Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions __tests__/label/remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ describe('remove', () => {
issueCommentEvent.comment.body = '/remove some-label'
const commentContext = new utils.MockContext(issueCommentEvent)

const removeSomeLabel = new utils.ObserveRequest()
server.use(
http.delete(
`${utils.api}/repos/Codertocat/Hello-World/issues/1/labels/some-label`,
utils.mockResponse(200),
utils.mockResponse(200, null, removeSomeLabel),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/issues/1`,
Expand All @@ -42,21 +43,26 @@ describe('remove', () => {
),
)

const setFailed = vi.spyOn(core, 'setFailed').mockImplementation(() => {})
await handleIssueComment(commentContext)
await expect(removeSomeLabel.called()).resolves.toBe('called')
expect(setFailed).not.toHaveBeenCalled()
})

it('removes multiple labels', async () => {
issueCommentEvent.comment.body = '/remove some-label some-other-label'
const commentContext = new utils.MockContext(issueCommentEvent)

const removeSomeLabel = new utils.ObserveRequest()
const removeSomeOtherLabel = new utils.ObserveRequest()
server.use(
http.delete(
`${utils.api}/repos/Codertocat/Hello-World/issues/1/labels/some-label`,
utils.mockResponse(200),
utils.mockResponse(200, null, removeSomeLabel),
),
http.delete(
`${utils.api}/repos/Codertocat/Hello-World/issues/1/labels/some-other-label`,
utils.mockResponse(200),
utils.mockResponse(200, null, removeSomeOtherLabel),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/issues/1`,
Expand All @@ -68,7 +74,12 @@ describe('remove', () => {
),
)

const setFailed = vi.spyOn(core, 'setFailed').mockImplementation(() => {})
await handleIssueComment(commentContext)
// every requested label is removed, not just the first
await expect(removeSomeLabel.called()).resolves.toBe('called')
await expect(removeSomeOtherLabel.called()).resolves.toBe('called')
expect(setFailed).not.toHaveBeenCalled()
})

it('fails if commenter is not collaborator', async () => {
Expand Down
12 changes: 12 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ export default antfu({
'node_modules/',
'**/node_modules/**/',
],
}, {
files: ['__tests__/**/*.test.ts'],
rules: {
// A test that drives the code but checks nothing passes whatever the code
// does. The extra names are this suite's own assertion helpers: the
// expectRequests/expectWindow family in __tests__/bundle and
// ObserveRequest.called()/notCalled() in __tests__/testUtils.ts, which
// reject on their own when the observed request is missing or present.
'test/expect-expect': ['error', {
assertFunctionNames: ['expect', 'expect*', '*.called', '*.notCalled'],
}],
},
})
Loading