-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
51 lines (41 loc) · 1.25 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
const run = require('.');
const core = require('@actions/core');
const mockAddRows = jest.fn();
jest.mock('@actions/core');
jest.mock('smartsheet', () => ({
createClient: jest.fn(() => ({
sheets: {
addRows: mockAddRows
}
}))
}));
describe('Add row to Smartsheet', () => {
beforeEach(() => {
jest.clearAllMocks();
const mockInputs = {
'access-token': 'my-access-token',
'sheet-id': 'my-sheet-id'
};
core.getInput = jest.fn(name => mockInputs[name]);
});
test('adds row to the sheet', async () => {
const rowId = 12345;
mockAddRows.mockImplementation(() => Promise.resolve({
result: {
id: rowId
}
}));
await run();
expect(mockAddRows).toHaveBeenCalledTimes(1);
expect(core.setFailed).toHaveBeenCalledTimes(0);
expect(core.setOutput).toHaveBeenCalledTimes(1);
expect(core.setOutput).toHaveBeenLastCalledWith('row-id', rowId);
});
test('error adding row to sheet', async () => {
mockAddRows.mockImplementation(() => Promise.reject('Some error occurred while adding the row'));
await run();
expect(mockAddRows).toHaveBeenCalledTimes(1);
expect(core.setFailed).toHaveBeenCalledTimes(1);
expect(core.setOutput).toHaveBeenCalledTimes(0);
});
});