2019-12-09 21:31:55 +09:00
|
|
|
import * as issue from '../src/issue'
|
2025-05-03 12:32:25 +00:00
|
|
|
import { IssueOption } from '../src/interface'
|
2019-12-09 21:31:55 +09:00
|
|
|
|
|
|
|
|
describe('getIssueOption', () => {
|
|
|
|
|
test('without assignee and label', () => {
|
|
|
|
|
process.env.INPUT_ISSUE_TITLE = 'npm audit found vulnerabilities'
|
|
|
|
|
|
|
|
|
|
const expected: IssueOption = {
|
|
|
|
|
title: 'npm audit found vulnerabilities',
|
|
|
|
|
body: 'hi',
|
2019-12-09 22:49:41 +09:00
|
|
|
assignees: undefined,
|
|
|
|
|
labels: undefined
|
2019-12-09 21:31:55 +09:00
|
|
|
}
|
|
|
|
|
expect(issue.getIssueOption('hi')).toEqual(expected)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('with 1 assignee and 1 label', () => {
|
|
|
|
|
process.env.INPUT_ISSUE_TITLE = 'npm audit found vulnerabilities'
|
|
|
|
|
process.env.INPUT_ISSUE_ASSIGNEES = 'alice'
|
|
|
|
|
process.env.INPUT_ISSUE_LABELS = 'foo'
|
|
|
|
|
|
|
|
|
|
const expected: IssueOption = {
|
|
|
|
|
title: 'npm audit found vulnerabilities',
|
|
|
|
|
body: 'hi',
|
|
|
|
|
assignees: ['alice'],
|
|
|
|
|
labels: ['foo']
|
|
|
|
|
}
|
|
|
|
|
expect(issue.getIssueOption('hi')).toEqual(expected)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('with 2 assignees and 2 labels', () => {
|
|
|
|
|
process.env.INPUT_ISSUE_TITLE = 'npm audit found vulnerabilities'
|
|
|
|
|
process.env.INPUT_ISSUE_ASSIGNEES = 'alice,bob'
|
|
|
|
|
process.env.INPUT_ISSUE_LABELS = 'foo,bar'
|
|
|
|
|
|
|
|
|
|
const expected: IssueOption = {
|
|
|
|
|
title: 'npm audit found vulnerabilities',
|
|
|
|
|
body: 'hi',
|
|
|
|
|
assignees: ['alice', 'bob'],
|
|
|
|
|
labels: ['foo', 'bar']
|
|
|
|
|
}
|
|
|
|
|
expect(issue.getIssueOption('hi')).toEqual(expected)
|
|
|
|
|
})
|
2021-10-08 17:47:46 +05:30
|
|
|
|
|
|
|
|
test('with label containing spaces', () => {
|
|
|
|
|
process.env.INPUT_ISSUE_TITLE = 'npm audit found vulnerabilities'
|
|
|
|
|
process.env.INPUT_ISSUE_ASSIGNEES = 'alice'
|
|
|
|
|
process.env.INPUT_ISSUE_LABELS = 'status: ready, work: frontend'
|
|
|
|
|
|
|
|
|
|
const expected: IssueOption = {
|
|
|
|
|
title: 'npm audit found vulnerabilities',
|
|
|
|
|
body: 'hi',
|
|
|
|
|
assignees: ['alice'],
|
|
|
|
|
labels: ['status: ready', 'work: frontend']
|
|
|
|
|
}
|
|
|
|
|
expect(issue.getIssueOption('hi')).toEqual(expected)
|
|
|
|
|
})
|
2019-12-09 21:31:55 +09:00
|
|
|
})
|
2020-05-27 15:18:45 -07:00
|
|
|
|
|
|
|
|
describe('getExistingIssueNumber', () => {
|
|
|
|
|
const expectedTitle = 'expected title'
|
|
|
|
|
const expectedIssueNumber = 12345
|
|
|
|
|
const repo = 'testRepo'
|
|
|
|
|
const owner = 'testOwner'
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
process.env.INPUT_ISSUE_TITLE = expectedTitle
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('gets existing open issue', async () => {
|
2025-05-02 14:03:34 +00:00
|
|
|
const getIssues = vi.fn()
|
2020-05-27 15:18:45 -07:00
|
|
|
getIssues.mockResolvedValue({
|
|
|
|
|
data: [
|
|
|
|
|
{
|
|
|
|
|
title: expectedTitle,
|
|
|
|
|
number: expectedIssueNumber
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
2025-05-03 12:32:25 +00:00
|
|
|
const result = await issue.getExistingIssueNumber(getIssues, {
|
|
|
|
|
repo,
|
|
|
|
|
owner
|
|
|
|
|
})
|
2020-05-27 15:18:45 -07:00
|
|
|
|
|
|
|
|
expect(getIssues).toHaveBeenCalledWith({
|
|
|
|
|
repo,
|
|
|
|
|
owner,
|
|
|
|
|
state: 'open'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result).toBe(expectedIssueNumber)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('returns null when there is no open issue', async () => {
|
2025-05-02 14:03:34 +00:00
|
|
|
const getIssues = vi.fn()
|
2025-05-03 12:32:25 +00:00
|
|
|
getIssues.mockResolvedValue({ data: [] })
|
2020-05-27 15:18:45 -07:00
|
|
|
|
2025-05-03 12:32:25 +00:00
|
|
|
const result = await issue.getExistingIssueNumber(getIssues, {
|
|
|
|
|
repo,
|
|
|
|
|
owner
|
|
|
|
|
})
|
2020-05-27 15:18:45 -07:00
|
|
|
|
|
|
|
|
expect(getIssues).toHaveBeenCalledWith({
|
|
|
|
|
repo,
|
|
|
|
|
owner,
|
|
|
|
|
state: 'open'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result).toBe(null)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('returns null when no issues match the issue title', async () => {
|
2025-05-02 14:03:34 +00:00
|
|
|
const getIssues = vi.fn()
|
2020-05-27 15:18:45 -07:00
|
|
|
getIssues.mockResolvedValue({
|
|
|
|
|
data: [
|
|
|
|
|
{
|
|
|
|
|
title: 'some random other issue',
|
|
|
|
|
number: 54321
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
|
2025-05-03 12:32:25 +00:00
|
|
|
const result = await issue.getExistingIssueNumber(getIssues, {
|
|
|
|
|
repo,
|
|
|
|
|
owner
|
|
|
|
|
})
|
2020-05-27 15:18:45 -07:00
|
|
|
|
|
|
|
|
expect(getIssues).toHaveBeenCalledWith({
|
|
|
|
|
repo,
|
|
|
|
|
owner,
|
|
|
|
|
state: 'open'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result).toBe(null)
|
|
|
|
|
})
|
|
|
|
|
})
|