-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathopenIssue.test.ts
More file actions
80 lines (66 loc) · 2.73 KB
/
openIssue.test.ts
File metadata and controls
80 lines (66 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {describe, it, expect, vi} from 'vitest'
// Mock generateIssueBody so we can inspect what screenshotRepo is passed
vi.mock('../src/generateIssueBody.js', () => ({
generateIssueBody: vi.fn((_finding, screenshotRepo: string) => `body with screenshotRepo=${screenshotRepo}`),
}))
import {openIssue} from '../src/openIssue.ts'
import {generateIssueBody} from '../src/generateIssueBody.ts'
const baseFinding = {
scannerType: 'axe',
ruleId: 'color-contrast',
url: 'https://example.com/page',
html: '<span>Low contrast</span>',
problemShort: 'elements must meet minimum color contrast ratio thresholds',
problemUrl: 'https://dequeuniversity.com/rules/axe/4.10/color-contrast?application=playwright',
solutionShort: 'ensure the contrast between foreground and background colors meets WCAG thresholds',
}
function mockOctokit() {
return {
request: vi.fn().mockResolvedValue({data: {id: 1, html_url: 'https://github.com/org/repo/issues/1'}}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any
}
describe('openIssue', () => {
it('passes screenshotRepo to generateIssueBody when provided', async () => {
const octokit = mockOctokit()
await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo')
expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/workflow-repo')
})
it('falls back to repoWithOwner when screenshotRepo is not provided', async () => {
const octokit = mockOctokit()
await openIssue(octokit, 'org/filing-repo', baseFinding)
expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/filing-repo')
})
it('posts to the correct filing repo, not the screenshot repo', async () => {
const octokit = mockOctokit()
await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo')
expect(octokit.request).toHaveBeenCalledWith(
'POST /repos/org/filing-repo/issues',
expect.objectContaining({
owner: 'org',
repo: 'filing-repo',
}),
)
})
it('includes the correct labels based on the finding', async () => {
const octokit = mockOctokit()
await openIssue(octokit, 'org/repo', baseFinding)
expect(octokit.request).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
labels: ['axe-scanning-issue', 'axe rule: color-contrast'],
}),
)
})
it('truncates long titles with ellipsis', async () => {
const octokit = mockOctokit()
const longFinding = {
...baseFinding,
problemShort: 'a'.repeat(300),
}
await openIssue(octokit, 'org/repo', longFinding)
const callArgs = octokit.request.mock.calls[0][1]
expect(callArgs.title.length).toBeLessThanOrEqual(256)
expect(callArgs.title).toMatch(/…$/)
})
})