-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathlabels.test.js
More file actions
148 lines (132 loc) · 5.12 KB
/
labels.test.js
File metadata and controls
148 lines (132 loc) · 5.12 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const Labels = require('../../../../lib/plugins/labels')
describe('Labels', () => {
let github
let log
function configure (config) {
const nop = false
return new Labels(nop, github, { owner: 'bkeepers', repo: 'test' }, config, log)
}
beforeEach(() => {
github = {
paginate: jest.fn().mockImplementation(() => Promise.resolve()),
repos: {
get: jest.fn().mockImplementation(() => Promise.resolve({}))
},
issues: {
listLabelsForRepo: {
endpoint: {
merge: jest.fn().mockImplementation(() => {})
}
},
createLabel: jest.fn().mockImplementation(() => Promise.resolve()),
deleteLabel: jest.fn().mockImplementation(() => Promise.resolve()),
updateLabel: jest.fn().mockImplementation(() => Promise.resolve())
}
}
log = { ...console, debug: jest.fn() }
})
describe('sync', () => {
it('syncs labels', () => {
github.paginate.mockReturnValueOnce(Promise.resolve([
{ name: 'no-change', color: 'FF0000', description: '' },
{ name: 'new-color', color: 0, description: '' }, // YAML treats `color: 000000` as an integer
{ name: 'new-description', color: '000000', description: '' },
{ name: 'update-me', color: '0000FF', description: '' },
{ name: 'delete-me', color: '000000', description: '' }
]))
const plugin = configure([
{ name: 'no-change', color: 'FF0000', description: '' },
{ name: 'new-name', oldname: 'update-me', color: 'FFFFFF', description: '' },
{ name: 'new-color', color: '999999', description: '' },
{ name: 'new-description', color: '#000000', description: 'Hello world' },
{ name: 'added', description: '' }
])
return plugin.sync().then(() => {
expect(github.issues.deleteLabel).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
name: 'delete-me',
headers: { accept: 'application/vnd.github.symmetra-preview+json' }
})
expect(github.issues.createLabel).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
name: 'added',
description: '',
headers: { accept: 'application/vnd.github.symmetra-preview+json' }
})
expect(github.issues.updateLabel).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
current_name: 'update-me',
name: 'new-name',
color: 'FFFFFF',
description: '',
headers: { accept: 'application/vnd.github.symmetra-preview+json' }
})
expect(github.issues.updateLabel).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
current_name: 'new-color',
name: 'new-color',
color: '999999',
description: '',
headers: { accept: 'application/vnd.github.symmetra-preview+json' }
})
expect(github.issues.updateLabel).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
current_name: 'new-description',
name: 'new-description',
color: '000000',
description: 'Hello world',
headers: { accept: 'application/vnd.github.symmetra-preview+json' }
})
expect(github.issues.deleteLabel).toHaveBeenCalledTimes(1)
expect(github.issues.updateLabel).toHaveBeenCalledTimes(3)
expect(github.issues.createLabel).toHaveBeenCalledTimes(1)
})
})
it('does not delete excluded labels', () => {
github.paginate.mockReturnValueOnce(Promise.resolve([
{ name: 'no-change', color: 'FF0000', description: '' },
{ name: 'keep-me', color: '000000', description: '' },
{ name: 'things-to-keep', color: '000000', description: '' },
{ name: 'released on @7.x.x', color: '000000', description: '' },
{ name: 'update-me', color: '0000FF', description: '' },
{ name: 'delete-me', color: '000000', description: '' }
]))
const plugin = configure({
exclude: [
{ name: 'keep' },
{ name: '^released' }
],
include: [
{ name: 'no-change', color: 'FF0000', description: '' },
{ name: 'new-name', oldname: 'update-me', color: 'FFFFFF', description: '' },
{ name: 'added', description: '' }
]
})
return plugin.sync().then(() => {
expect(github.issues.deleteLabel).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
name: 'delete-me',
headers: { accept: 'application/vnd.github.symmetra-preview+json' }
})
expect(github.issues.updateLabel).toHaveBeenCalledWith({
owner: 'bkeepers',
repo: 'test',
current_name: 'update-me',
name: 'new-name',
color: 'FFFFFF',
description: '',
headers: { accept: 'application/vnd.github.symmetra-preview+json' }
})
expect(github.issues.deleteLabel).toHaveBeenCalledTimes(1)
expect(github.issues.updateLabel).toHaveBeenCalledTimes(1)
expect(github.issues.createLabel).toHaveBeenCalledTimes(1)
})
})
})
})