-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-client.test.js
72 lines (66 loc) · 2.7 KB
/
github-client.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const client = require('./github-client');
const core = require('@actions/core');
const github = require('@actions/github');
jest.mock('@actions/core');
jest.mock('@actions/github');
beforeEach(() => {
delete client.getOctokit.octokit;
});
test('get pr info no octokit', async () => {
core.getInput.mockImplementation(() => "");
console.log = jest.fn();
const prInfo = await client.getPRInfo('https://example.com/repos/test_account/test_repo/pull/3');
expect(prInfo).toBeUndefined();
expect(console.log).toHaveBeenCalledWith("No value set for github-token");
expect(console.log).toHaveBeenCalledWith("Failed to initialize octokit for retrieving PR info");
});
test('get pr info', async () => {
core.getInput.mockImplementation(() => "aaaaaaaaaaaaaaaaaa");
const mocktokit = {
rest: {
pulls : {
get : async (params) => {
expect(params.owner).toBe("test_account");
expect(params.repo).toBe("test_repo");
expect(params.pull_number).toBe("3");
return {
data: "test"
}
}
}
}
}
github.getOctokit.mockImplementation(() => mocktokit);
const prInfo = await client.getPRInfo('https://example.com/repos/test_account/test_repo/pull/3');
expect(prInfo).toBe("test");
});
test('get user permission level no octokit', async () => {
core.getInput.mockImplementation(() => "");
console.log = jest.fn();
const permissionLevel = await client.getUserPermissionLevel('test_owner', 'test_repo', 'test_user');
expect(permissionLevel).toBeUndefined();
expect(console.log).toHaveBeenCalledWith("No value set for github-token");
expect(console.log).toHaveBeenCalledWith("Failed to initialize octokit for retrieving user permission level");
});
test('get user permission level', async () => {
core.getInput.mockImplementation(() => "aaaaaaaaaaaaaaaaaa");
const mocktokit = {
rest: {
repos : {
getCollaboratorPermissionLevel : async (params) => {
expect(params.owner).toBe("test_owner");
expect(params.repo).toBe("test_repo");
expect(params.username).toBe("test_user");
return {
data: {
permission: "read"
}
}
}
}
}
}
github.getOctokit.mockImplementation(() => mocktokit);
const permissionLevel = await client.getUserPermissionLevel('test_owner', 'test_repo', 'test_user');
expect(permissionLevel).toStrictEqual({permission: "read"});
});