-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathcollaborators.test.js
More file actions
69 lines (59 loc) · 2.25 KB
/
collaborators.test.js
File metadata and controls
69 lines (59 loc) · 2.25 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
const Collaborators = require('../../../../lib/plugins/collaborators')
describe('Collaborators', () => {
let github
function configure (config) {
const log = { ...console, debug: jest.fn() }
return new Collaborators(undefined, github, { owner: 'bkeepers', repo: 'test' }, config, log)
}
beforeEach(() => {
github = {
repos: {
listInvitations: jest.fn().mockResolvedValue([]),
deleteInvitation: jest.fn().mockResolvedValue(),
updateInvitation: jest.fn().mockResolvedValue(),
listCollaborators: jest.fn().mockResolvedValue([]),
removeCollaborator: jest.fn().mockResolvedValue(),
addCollaborator: jest.fn().mockResolvedValue()
}
}
})
describe('sync', () => {
it('syncs collaborators', () => {
const plugin = configure([
{ username: 'bkeepers', permission: 'admin' },
{ username: 'added-user', permission: 'push' },
{ username: 'updated-permission', permission: 'push' },
{ username: 'DIFFERENTcase', permission: 'push' }
])
github.repos.listCollaborators.mockResolvedValueOnce({
data: [
{ login: 'bkeepers', permissions: { admin: true, push: true, pull: true } },
{ login: 'updated-permission', permissions: { admin: false, push: false, pull: true } },
{ login: 'removed-user', permissions: { admin: false, push: true, pull: true } },
{ login: 'differentCase', permissions: { admin: false, push: true, pull: true } }
]
})
return plugin.sync().then(() => {
expect(github.repos.addCollaborator).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
username: 'added-user',
permission: 'push'
})
expect(github.repos.addCollaborator).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
username: 'updated-permission',
permission: 'push'
})
expect(github.repos.addCollaborator).toHaveBeenCalledTimes(2)
expect(github.repos.removeCollaborator).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
username: 'removed-user'
})
expect(github.repos.removeCollaborator).toHaveBeenCalledTimes(1)
})
})
})
})