-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
94 lines (83 loc) · 2.44 KB
/
test.js
File metadata and controls
94 lines (83 loc) · 2.44 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
const fs = require('fs')
const path = require('path')
const nock = require('nock')
const { Probot, ProbotOctokit } = require('probot')
const createScheduler = require('./')
const githubAPI = nock('https://api.github.com').persist()
const payload = require('./fixtures/installation-created.json')
const privateKey = fs.readFileSync(
path.join(__dirname, 'fixtures/mock-cert.pem'),
'utf-8'
)
describe('Schedules intervals for a repository', () => {
let probot
let mockHandler = jest.fn()
beforeEach(() => {
nock.disableNetConnect()
probot = new Probot({
appId: 2,
privateKey: privateKey,
// Disable throttling & retrying requests for easier testing
Octokit: ProbotOctokit.defaults({
retry: { enabled: false },
throttle: { enabled: false }
})
})
probot.load((app) => {
createScheduler(app, {
delay: false,
interval: 500
})
app.on('schedule.repository', mockHandler)
})
})
it('gets a page of repositories', async (done) => {
// Mock authed by access token.
githubAPI.post('/app/installations/2/access_tokens')
.reply(200, {
token: 'test',
permissions: {
issues: 'write'
}
})
// Mock list all installation.
githubAPI.get(/\/app\/installations/)
.reply(200, [
{
'id': 2,
'account': {
'login': 'octocat',
'id': 2
},
'app_id': 2
}
])
// Mock list all repositories.
const pages = {
1: {
body: [{ id: 1 }],
headers: {
Link: '<https://api.github.com/installation/repositories?page=2&per_page=100>; rel="next"',
'X-GitHub-Media-Type': 'github.v3; format=json'
}
},
2: {
body: [{ id: 2 }]
}
}
githubAPI.get('/installation/repositories')
.query({ per_page: 100 })
.reply(200, pages[1].body, pages[1].headers)
.get('/installation/repositories')
.query({ page: 2, per_page: 100 })
.reply(200, pages[2].body)
await probot.receive({ name: 'installation', payload })
setTimeout(() => {
expect(mockHandler).toBeCalled()
// The handler is called four times because when the delay time is 0ms and the interval is 500ms,
// the two repository trigger a total of 4 times within the time range of 0 to 750ms
expect(mockHandler.mock.calls.length).toBe(4)
done()
}, 750)
})
})