Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Commit 3ce597a

Browse files
committed
test: ensure pending state is always sent
1 parent 249a672 commit 3ce597a

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

test/bot.test.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ const { createRobot } = require('probot')
55
// Ours
66
const app = require('../index')
77
const githubMock = require('./mocks/github')
8-
const payload = require('./payload')
8+
const events = require('./events')
9+
10+
// Constants
11+
const baseStatus = {
12+
sha: '123456789',
13+
repo: 'test-commitlint-bot',
14+
owner: 'ahmed-taj',
15+
context: 'commitlint-bot',
16+
target_url: 'http://npm.im/@commitlint/config-angular#problems'
17+
}
918

1019
describe('commitlint-bot', () => {
1120
let robot
@@ -24,10 +33,18 @@ describe('commitlint-bot', () => {
2433

2534
describe('update status to pending', () => {
2635
it('calls createStatus with "pending"', async () => {
36+
const pending = {
37+
...baseStatus,
38+
state: 'pending',
39+
description: 'Waiting for the status to be reported'
40+
}
2741
// Simulates delivery of a payload
28-
await robot.receive(payload.opened)
29-
// expect(github.repos.createStatus).toHaveBeenCalled()
30-
expect(true).toBeTruthy()
42+
// New PR
43+
await robot.receive(events.opened)
44+
expect(github.repos.createStatus).toHaveBeenCalledWith(pending)
45+
// Updated PR
46+
await robot.receive(events.synchronize)
47+
expect(github.repos.createStatus).toHaveBeenCalledWith(pending)
3148
})
3249
})
3350
})

test/events/pull_request.opened.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"login": "ahmed-taj"
99
},
1010
"head": {
11-
"sha": "5c1dc266b4aafa28ce6aa5cafd5b65b87febd5fc",
11+
"sha": "123456789",
1212
"user": {
1313
"login": "ahmed-taj"
1414
}

test/events/pull_request.synchronize.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"login": "ahmed-taj"
99
},
1010
"head": {
11-
"sha": "f53aa23db7a778a93539e44069e03111b2dd033b",
11+
"sha": "123456789",
1212
"user": {
1313
"login": "ahmed-taj"
1414
}

test/mocks/github.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
const expect = require('expect')
33

44
// Mock necessary GitHub APIs here
5-
module.exports = () => {
5+
module.exports = data => {
6+
const commits = data || [
7+
{ commit: { message: 'fix: issue #1' } },
8+
{ commit: { message: 'fix: issue #2' } },
9+
{ commit: { message: 'fix: issue #3' } },
10+
{ commit: { message: 'fix: issue #4' } }
11+
]
612
return {
713
repos: {
814
createStatus: expect.createSpy()
15+
},
16+
pullRequests: {
17+
getCommits: expect.createSpy().andReturn(Promise.resolve({ commits }))
18+
},
19+
paginate: (fn, callback) => {
20+
callback(fn)
921
}
1022
}
1123
}

0 commit comments

Comments
 (0)