Support de-duping issues (#65)
* De-dupe against open issues when dedupe_issues = true * Update README * Fix compile errors * Add unit tests for issue.ts
This commit is contained in:
@@ -42,3 +42,72 @@ describe('getIssueOption', () => {
|
||||
expect(issue.getIssueOption('hi')).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
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 () => {
|
||||
const getIssues = jest.fn()
|
||||
getIssues.mockResolvedValue({
|
||||
data: [
|
||||
{
|
||||
title: expectedTitle,
|
||||
number: expectedIssueNumber
|
||||
}
|
||||
]
|
||||
})
|
||||
const result = await issue.getExistingIssueNumber(getIssues, {repo, owner})
|
||||
|
||||
expect(getIssues).toHaveBeenCalledWith({
|
||||
repo,
|
||||
owner,
|
||||
state: 'open'
|
||||
})
|
||||
|
||||
expect(result).toBe(expectedIssueNumber)
|
||||
})
|
||||
|
||||
test('returns null when there is no open issue', async () => {
|
||||
const getIssues = jest.fn()
|
||||
getIssues.mockResolvedValue({data: []})
|
||||
|
||||
const result = await issue.getExistingIssueNumber(getIssues, {repo, owner})
|
||||
|
||||
expect(getIssues).toHaveBeenCalledWith({
|
||||
repo,
|
||||
owner,
|
||||
state: 'open'
|
||||
})
|
||||
|
||||
expect(result).toBe(null)
|
||||
})
|
||||
|
||||
test('returns null when no issues match the issue title', async () => {
|
||||
const getIssues = jest.fn()
|
||||
getIssues.mockResolvedValue({
|
||||
data: [
|
||||
{
|
||||
title: 'some random other issue',
|
||||
number: 54321
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const result = await issue.getExistingIssueNumber(getIssues, {repo, owner})
|
||||
|
||||
expect(getIssues).toHaveBeenCalledWith({
|
||||
repo,
|
||||
owner,
|
||||
state: 'open'
|
||||
})
|
||||
|
||||
expect(result).toBe(null)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user