Skip to content
Merged
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
41 changes: 40 additions & 1 deletion __tests__/utils/labeling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { setupServer } from 'msw/node'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'

import { handleIssueComment } from '../../src/issueComment/handleIssueComment'
import { addPrefix, assertLabelsExist, getLabelConfig, labelIssue } from '../../src/utils/labeling'
import { addPrefix, assertLabelsExist, getLabelConfig, labelIssue, removeLabels } from '../../src/utils/labeling'
import { newOctokit } from '../../src/utils/octokit'
import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json'

Expand Down Expand Up @@ -162,6 +162,45 @@ describe('labelIssue refuses labels the repository does not have', () => {
})
})

describe('removeLabels', () => {
const context = new utils.MockContext(issueCommentEvent)
const repo = `${utils.api}/repos/Codertocat/Hello-World`
let octokit: Octokit

beforeEach(() => {
utils.setupActionsEnv()
octokit = newOctokit('some-token')
})

it('keeps removing the later labels after an earlier one is already gone', async () => {
const deleted: string[] = []
server.use(
http.delete(`${repo}/issues/1/labels/:name`, ({ params }) => {
deleted.push(String(params.name))
return new Response(null, { status: params.name === 'gone' ? 404 : 200 })
}),
)

await expect(removeLabels(octokit, context, 1, ['gone', 'kind/bug', 'still-there'])).resolves.toBeUndefined()

expect(deleted).toEqual(['gone', 'kind/bug', 'still-there'])
})

it('stops at the first failure that is not a 404 and names the label', async () => {
const deleted: string[] = []
server.use(
http.delete(`${repo}/issues/1/labels/:name`, ({ params }) => {
deleted.push(String(params.name))
return new Response(null, { status: params.name === 'broken' ? 500 : 200 })
}),
)

await expect(removeLabels(octokit, context, 1, ['first', 'broken', 'never'])).rejects.toThrow('could not remove label broken')

expect(deleted).toEqual(['first', 'broken'])
})
})

describe('getLabelConfig', () => {
const context = new utils.MockContext(issueCommentEvent)
let octokit: Octokit
Expand Down
Loading