Repository navigation
Expand file tree
/
Copy pathnode-repo.test.js
More file actions
66 lines (52 loc) · 1.87 KB
/
Copy pathnode-repo.test.js
File metadata and controls
66 lines (52 loc) · 1.87 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
import test from 'node:test'
import fetchMock from 'fetch-mock'
import * as nodeRepo from '../../lib/node-repo.js'
import logger from '../../lib/logger.js'
import readFixture from '../read-fixture.js'
fetchMock.mockGlobal()
test('getBotPrLabels(): returns labels added by nodejs-github-bot', (t, done) => {
const events = readFixture('pull-request-events.json')
const owner = 'nodejs'
const repo = 'node5'
const prId = '1'
const urlPattern = `glob:https://api.github.com/repos/${owner}/${repo}/issues/${prId}/events?*`
fetchMock.route(urlPattern, events.data)
t.plan(2)
nodeRepo.getBotPrLabels({ owner, repo, prId }, (_, labels) => {
t.assert.deepStrictEqual(labels, ['testlabel'])
t.assert.strictEqual(fetchMock.callHistory.called(urlPattern), true)
done()
})
})
test('getBotPrLabels(): returns net labels added/removed by nodejs-github-bot', (t, done) => {
const events = readFixture('pull-request-events-2.json')
const owner = 'nodejs'
const repo = 'node6'
const prId = '2'
const urlPattern = `glob:https://api.github.com/repos/${owner}/${repo}/issues/${prId}/events?*`
fetchMock.route(
urlPattern,
events.data
)
t.plan(2)
nodeRepo.getBotPrLabels({ owner, repo, prId }, (_, labels) => {
t.assert.deepStrictEqual(labels, [])
t.assert.strictEqual(fetchMock.callHistory.called(urlPattern), true)
done()
})
})
test('removeLabelFromPR(): should remove label', async (t) => {
const owner = 'nodejs'
const repo = 'node7'
const prId = '3'
const label = '3'
const urlPattern = `https://api.github.com/repos/${owner}/${repo}/issues/${prId}/labels/${label}`
fetchMock.route(
urlPattern,
200
)
t.plan(2)
const response = await nodeRepo.removeLabelFromPR({ owner, repo, prId, logger }, label)
t.assert.deepStrictEqual(label, response)
t.assert.strictEqual(fetchMock.callHistory.called(urlPattern), true)
})