-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathautolinks.test.js
More file actions
147 lines (132 loc) · 5.42 KB
/
autolinks.test.js
File metadata and controls
147 lines (132 loc) · 5.42 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
const Autolinks = require('../../../../lib/plugins/autolinks')
describe('Autolinks', () => {
const repo = { owner: 'owner', repo: 'repo' }
let github
function configure (config) {
const log = { ...console, debug: jest.fn() }
const nop = false
const errors = []
return new Autolinks(nop, github, repo, config, log, errors)
}
beforeEach(() => {
github = {
repos: {
listAutolinks: jest.fn().mockResolvedValue([]),
createAutolink: jest.fn().mockResolvedValue(),
deleteAutolink: jest.fn().mockResolvedValue()
}
}
})
describe('sync', () => {
it('syncs autolinks', () => {
const plugin = configure([
{ key_prefix: 'ADD-', url_template: 'https://test/<num>' },
{ key_prefix: 'SAME-', url_template: 'https://test/<num>' },
{ key_prefix: 'NEW_URL-', url_template: 'https://new-url/<num>' },
{ key_prefix: 'SAME_ALPHA-UNDEFINED-', url_template: 'https://test/<num>' },
{ key_prefix: 'SAME_ALPHA-FALSE-', url_template: 'https://test/<num>', is_alphanumeric: false },
{ key_prefix: 'SAME_ALPHA-TRUE-', url_template: 'https://test/<num>', is_alphanumeric: true },
{ key_prefix: 'NEW_ALPHA-UNDEFINED-', url_template: 'https://test/<num>' },
{ key_prefix: 'NEW_ALPHA-FALSE-', url_template: 'https://test/<num>', is_alphanumeric: false },
{ key_prefix: 'NEW_ALPHA-TRUE-', url_template: 'https://test/<num>', is_alphanumeric: true }
])
github.repos.listAutolinks.mockResolvedValueOnce({
data: [
{ id: '1', key_prefix: 'SAME-', url_template: 'https://test/<num>', is_alphanumeric: true },
{ id: '2', key_prefix: 'REMOVE-', url_template: 'https://test/<num>', is_alphanumeric: true },
{ id: '3', key_prefix: 'NEW_URL-', url_template: 'https://current-url/<num>', is_alphanumeric: true },
{ id: '4', key_prefix: 'SAME_ALPHA-UNDEFINED-', url_template: 'https://test/<num>', is_alphanumeric: true },
{ id: '5', key_prefix: 'SAME_ALPHA-FALSE-', url_template: 'https://test/<num>', is_alphanumeric: false },
{ id: '6', key_prefix: 'SAME_ALPHA-TRUE-', url_template: 'https://test/<num>', is_alphanumeric: true },
{ id: '7', key_prefix: 'NEW_ALPHA-UNDEFINED-', url_template: 'https://test/<num>', is_alphanumeric: false },
{ id: '8', key_prefix: 'NEW_ALPHA-FALSE-', url_template: 'https://test/<num>', is_alphanumeric: true },
{ id: '9', key_prefix: 'NEW_ALPHA-TRUE-', url_template: 'https://test/<num>', is_alphanumeric: false }
]
})
return plugin.sync().then(() => {
expect(github.repos.createAutolink).toHaveBeenCalledWith({
key_prefix: 'ADD-',
url_template: 'https://test/<num>',
is_alphanumeric: true,
...repo
})
expect(github.repos.deleteAutolink).toHaveBeenCalledWith({
autolink_id: '2',
...repo
})
expect(github.repos.deleteAutolink).toHaveBeenCalledWith({
autolink_id: '3',
...repo
})
expect(github.repos.createAutolink).toHaveBeenCalledWith({
key_prefix: 'NEW_URL-',
url_template: 'https://new-url/<num>',
is_alphanumeric: true,
...repo
})
expect(github.repos.deleteAutolink).not.toHaveBeenCalledWith({
autolink_id: '4',
...repo
})
expect(github.repos.createAutolink).not.toHaveBeenCalledWith({
key_prefix: 'SAME_ALPHA-UNDEFINED-',
url_template: 'https://test/<num>',
is_alphanumeric: true,
...repo
})
expect(github.repos.deleteAutolink).not.toHaveBeenCalledWith({
autolink_id: '5',
...repo
})
expect(github.repos.createAutolink).not.toHaveBeenCalledWith({
key_prefix: 'SAME_ALPHA-FALSE-',
url_template: 'https://test/<num>',
is_alphanumeric: false,
...repo
})
expect(github.repos.deleteAutolink).not.toHaveBeenCalledWith({
autolink_id: '6',
...repo
})
expect(github.repos.createAutolink).not.toHaveBeenCalledWith({
key_prefix: 'SAME_ALPHA-TRUE-',
url_template: 'https://test/<num>',
is_alphanumeric: true,
...repo
})
expect(github.repos.deleteAutolink).toHaveBeenCalledWith({
autolink_id: '7',
...repo
})
expect(github.repos.createAutolink).toHaveBeenCalledWith({
key_prefix: 'NEW_ALPHA-UNDEFINED-',
url_template: 'https://test/<num>',
is_alphanumeric: true,
...repo
})
expect(github.repos.deleteAutolink).toHaveBeenCalledWith({
autolink_id: '8',
...repo
})
expect(github.repos.createAutolink).toHaveBeenCalledWith({
key_prefix: 'NEW_ALPHA-FALSE-',
url_template: 'https://test/<num>',
is_alphanumeric: false,
...repo
})
expect(github.repos.deleteAutolink).toHaveBeenCalledWith({
autolink_id: '9',
...repo
})
expect(github.repos.createAutolink).toHaveBeenCalledWith({
key_prefix: 'NEW_ALPHA-TRUE-',
url_template: 'https://test/<num>',
is_alphanumeric: true,
...repo
})
expect(github.repos.deleteAutolink).toHaveBeenCalledTimes(5)
expect(github.repos.createAutolink).toHaveBeenCalledTimes(5)
})
})
})
})