-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
53 lines (45 loc) · 1.45 KB
/
index.test.js
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
const core = require('@actions/core');
const { sendVulnerabilities} = require('../src/sendCveTest');
require('../src/index');
jest.mock('@actions/core', () => ({
getInput: jest.fn()
.mockReturnValueOnce('pr_number')
.mockReturnValueOnce('token'),
setOutput: jest.fn(),
setFailed: jest.fn(),
}));
jest.mock('@actions/github', () => ({
getOctokit: jest.fn().mockReturnValue({
rest: {
pulls: {
listFiles: jest.fn().mockResolvedValue([]),
get: jest.fn().mockResolvedValue({ data: { body: 'Description with valid format' } }),
},
issues: {
createComment: jest.fn(),
},
},
context: {
repo: {},
},
}),
}));
jest.mock('fs', () => ({
readFileSync: jest.fn().mockReturnValue('file content'),
}));
jest.mock('../src/sendCveTest', () => ({
sendVulnerabilities: jest.fn(),
fileContent: 'file content',
}));
describe('Main Function', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should handle successful execution with valid description', async () => {
sendVulnerabilities.mockImplementation((idNumber, callback) => {
callback('Upload successful');
});
expect(core.getInput).toHaveBeenCalledWith('pr_number', { required: true });
expect(core.getInput).toHaveBeenCalledWith('token', { required: true });
});
});