/
index.js
67 lines (57 loc) · 2.25 KB
/
index.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
62
63
64
65
66
67
const expect = require('expect')
const { Application } = require('probot')
const { GitHubAPI } = require('probot/lib/github')
const plugin = require('..')
const successPayload = require('./events/successPayload')
const successIssueRes = require('./events/successIssueRes')
const failPayload = require('./events/failPayload')
const failIssueRes = require('./events/failIssueRes')
describe('new-issue-welcome', () => {
let app
let github
beforeEach(() => {
app = new Application()
plugin(app)
github = new GitHubAPI()
app.auth = () => Promise.resolve(github)
})
function makeResponse (msg) {
return Promise.resolve({ data: { content: Buffer.from(msg).toString('base64') } })
}
describe('new-issue-welcome success', () => {
it('posts a comment because it is a user\'s first issue opened', async () => {
expect.spyOn(github.repos, 'getContents').andReturn(makeResponse(`newIssueWelcomeComment: >\n woot woot`))
expect.spyOn(github.issues, 'listForRepo').andReturn(Promise.resolve(successIssueRes))
expect.spyOn(github.issues, 'createComment')
await app.receive(successPayload)
expect(github.issues.listForRepo).toHaveBeenCalledWith({
owner: 'hiimbex',
repo: 'testing-things',
state: 'all',
creator: 'hiimbex-test'
})
expect(github.repos.getContents).toHaveBeenCalledWith({
owner: 'hiimbex',
repo: 'testing-things',
path: '.github/config.yml'
})
expect(github.issues.createComment).toHaveBeenCalled()
})
})
describe('new-issue-welcome failure', () => {
it('posts a comment because it is a user\'s first issue opened', async () => {
expect.spyOn(github.repos, 'getContents').andReturn(makeResponse(`newIssueWelcomeComment: >\n woot woot`))
expect.spyOn(github.issues, 'listForRepo').andReturn(Promise.resolve(failIssueRes))
expect.spyOn(github.issues, 'createComment')
await app.receive(failPayload)
expect(github.issues.listForRepo).toHaveBeenCalledWith({
owner: 'hiimbex',
repo: 'testing-things',
state: 'all',
creator: 'hiimbex'
})
expect(github.repos.getContents).toNotHaveBeenCalled()
expect(github.issues.createComment).toNotHaveBeenCalled()
})
})
})