-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathindex.test.ts
More file actions
84 lines (73 loc) · 1.87 KB
/
index.test.ts
File metadata and controls
84 lines (73 loc) · 1.87 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
81
82
83
84
import {beforeEach, describe, expect, it, vi} from 'vitest'
const {octokitCtorMock, getInputMock} = vi.hoisted(() => ({
octokitCtorMock: vi.fn(),
getInputMock: vi.fn(),
}))
vi.mock('@actions/core', () => ({
getInput: getInputMock,
info: vi.fn(),
debug: vi.fn(),
warning: vi.fn(),
setOutput: vi.fn(),
setFailed: vi.fn(),
}))
vi.mock('@octokit/core', () => ({
Octokit: {
plugin: vi.fn(() => octokitCtorMock),
},
}))
vi.mock('@octokit/plugin-throttling', () => ({
throttling: vi.fn(),
}))
describe('fix action index', () => {
beforeEach(() => {
vi.resetModules()
vi.clearAllMocks()
})
it('passes baseUrl to Octokit when base_url input is provided', async () => {
getInputMock.mockImplementation((name: string) => {
switch (name) {
case 'issues':
return '[]'
case 'repository':
return 'org/repo'
case 'token':
return 'token'
case 'base_url':
return 'https://ghe.example.com/api/v3'
default:
return ''
}
})
const {default: run} = await import('../src/index.ts')
await run()
expect(octokitCtorMock).toHaveBeenCalledWith(
expect.objectContaining({
auth: 'token',
baseUrl: 'https://ghe.example.com/api/v3',
}),
)
})
it('uses Octokit default API URL when base_url input is not provided', async () => {
getInputMock.mockImplementation((name: string) => {
switch (name) {
case 'issues':
return '[]'
case 'repository':
return 'org/repo'
case 'token':
return 'token'
default:
return ''
}
})
const {default: run} = await import('../src/index.ts')
await run()
expect(octokitCtorMock).toHaveBeenCalledWith(
expect.objectContaining({
auth: 'token',
baseUrl: undefined,
}),
)
})
})