-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinputs.test.ts
More file actions
79 lines (71 loc) · 2.11 KB
/
Copy pathinputs.test.ts
File metadata and controls
79 lines (71 loc) · 2.11 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
// Mock @actions/core before any imports
jest.mock('@actions/core', () => ({
warning: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
getInput: jest.fn()
}))
import * as core from '@actions/core'
import {getInputs} from '../src/inputs'
const mockGetInput = core.getInput as jest.MockedFunction<typeof core.getInput>
describe('getInputs', () => {
beforeEach(() => {
jest.clearAllMocks()
// Default mock implementation — no inputs set
mockGetInput.mockReturnValue('')
})
it('requires base-ref', () => {
mockGetInput.mockImplementation((name: string) => {
if (name === 'base-ref') return ''
return ''
})
expect(() => getInputs()).toThrow('base-ref is required')
})
it('parses all inputs correctly', () => {
mockGetInput.mockImplementation((name: string) => {
switch (name) {
case 'base-ref':
return 'v1.0'
case 'head-ref':
return 'v2.0'
case 'instructions':
return 'guide.md'
case 'model':
return 'gpt-4'
case 'pr-strategy':
return 'github-api'
default:
return ''
}
})
const inputs = getInputs()
expect(inputs.baseRef).toBe('v1.0')
expect(inputs.headRef).toBe('v2.0')
expect(inputs.model).toBe('gpt-4')
expect(inputs.prStrategy).toBe('github-api')
})
it('defaults head-ref to HEAD', () => {
mockGetInput.mockImplementation((name: string) => {
if (name === 'base-ref') return 'v1.0'
return ''
})
const inputs = getInputs()
expect(inputs.headRef).toBe('HEAD')
})
it('defaults pr-strategy to merge-commits', () => {
mockGetInput.mockImplementation((name: string) => {
if (name === 'base-ref') return 'v1.0'
return ''
})
const inputs = getInputs()
expect(inputs.prStrategy).toBe('merge-commits')
})
it('rejects invalid pr-strategy', () => {
mockGetInput.mockImplementation((name: string) => {
if (name === 'base-ref') return 'v1.0'
if (name === 'pr-strategy') return 'invalid'
return ''
})
expect(() => getInputs()).toThrow('Invalid pr-strategy')
})
})