-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathautolinks.test.js
61 lines (56 loc) · 1.9 KB
/
autolinks.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
const path = require('path')
const fs = require('fs')
const { CREATED, NO_CONTENT, OK } = require('http-status-codes')
const settings = require('../../../lib/settings')
const { buildTriggerEvent, initializeNock, loadInstance, repository, teardownNock } = require('../common')
describe('autolinks plugin', function () {
let probot, githubScope
beforeEach(() => {
githubScope = initializeNock()
probot = loadInstance()
})
afterEach(() => {
teardownNock(githubScope)
})
it('syncs autolinks', async () => {
const pathToConfig = path.resolve(__dirname, '..', '..', 'fixtures', 'autolinks-config.yml')
const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8'))
const config = configFile.toString()
githubScope
.get(`/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(settings.FILE_NAME)}`)
.reply(OK, config)
githubScope
.patch(`/repos/${repository.owner.name}/${repository.name}`)
.reply(200)
githubScope
.get(`/repos/${repository.owner.name}/${repository.name}/autolinks?per_page=100`)
.reply(
OK,
[
{
id: 1,
key_prefix: 'ASDF-',
url_template: 'https://jira.company.com/browse/ASDF-<num>'
},
{
id: 2,
key_prefix: 'TEST-',
url_template: 'https://jira.company.com/browse/TEST-<num>'
}
]
)
githubScope
.post(`/repos/${repository.owner.name}/${repository.name}/autolinks`, body => {
expect(body).toMatchObject({
key_prefix: 'BOLIGRAFO-',
url_template: 'https://jira.company.com/browse/BOLIGRAFO-<num>'
})
return true
})
.reply(CREATED)
githubScope
.delete(`/repos/${repository.owner.name}/${repository.name}/autolinks/2`)
.reply(NO_CONTENT)
await probot.receive(buildTriggerEvent())
})
})