forked from probot/adapter-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
56 lines (43 loc) · 1.53 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
54
55
56
jest.mock('uuid');
jest.mock('@actions/core');
jest.mock('probot');
const uuid = require('uuid');
const core = require('@actions/core');
const { Probot } = require('probot');
const adapt = require('./index');
describe('probot-actions-adapter', () => {
let probot;
beforeEach(() => {
// Mock uuid
uuid.v4 = jest.fn(() => 'uuid-v4');
// Mock probot
probot = {
setup: jest.fn(),
receive: jest.fn(async () => true)
};
Probot.mockImplementation(() => {
return probot;
});
});
test('that we can adapt a single handler', async () => {
const handler = () => {};
await adapt(handler);
expect(Probot).toHaveBeenCalledWith({ githubToken: 'GITHUB_TOKEN' });
expect(probot.setup).toHaveBeenCalledWith([handler]);
expect(probot.receive).toHaveBeenCalledWith({ id: 'uuid-v4', name: 'push', payload: { commits: [] } });
});
test('that we can adapt many handlers', async () => {
const handlers = [() => {}, () => {}];
await adapt(...handlers);
expect(Probot).toHaveBeenCalledWith({ githubToken: 'GITHUB_TOKEN' });
expect(probot.setup).toHaveBeenCalledWith(handlers);
expect(probot.receive).toHaveBeenCalledWith({ id: 'uuid-v4', name: 'push', payload: { commits: [] } });
});
test('that failures are handled', async () => {
probot.receive = jest.fn(async () => {
throw new Error('oh noes');
});
await expect(adapt(() => {})).rejects.toThrow('oh noes');
expect(core.setFailed).toHaveBeenCalledWith('Action failed with error: oh noes');
});
});