Skip to content

Commit 2e45fdd

Browse files
committed
Added a couple of tests
1 parent f342a05 commit 2e45fdd

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
},
2424
"devDependencies": {
2525
"eventsource": "^0.2.1",
26+
"nock": "^8.0.0",
2627
"nodemon": "^1.9.1",
2728
"request": "^2.72.0",
2829
"standard": "^6.0.7",
30+
"supertest": "^1.2.0",
2931
"tap": "^5.7.1"
3032
}
3133
}

scripts/node-jenkins-status.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ module.exports = function (app) {
99
repoName: 'node'
1010
}, req.body)
1111

12-
res.end()
12+
res.status(201).end()
1313
})
1414
}

test/push-jenkins-update.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use strict'
2+
3+
// POST /repos/:owner/:repo/statuses/:sha
4+
5+
const tap = require('tap')
6+
const fs = require('fs')
7+
const path = require('path')
8+
const url = require('url')
9+
const nock = require('nock')
10+
const supertest = require('supertest')
11+
12+
const app = require('../app')
13+
14+
tap.test('Sends POST requests to /repos/nodejs/node/statuses/<SHA>', (t) => {
15+
const fixture = readFixture('success-payload.json')
16+
const scope = nock('https://api.github.com')
17+
.filteringPath(ignoreQueryParams)
18+
.post('/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1')
19+
.reply(201)
20+
21+
t.plan(1)
22+
t.tearDown(() => scope.done())
23+
24+
supertest(app)
25+
.post('/node/jenkins')
26+
.send(fixture)
27+
.expect(201)
28+
.end((err, res) => {
29+
t.equal(err, null)
30+
})
31+
})
32+
33+
tap.test('Forwards payload provided in incoming POST to GitHub status API', (t) => {
34+
const fixture = readFixture('success-payload.json')
35+
const scope = nock('https://api.github.com')
36+
.filteringPath(ignoreQueryParams)
37+
.post('/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1', {
38+
state: 'success',
39+
context: 'test/osx',
40+
description: 'tests passed',
41+
target_url: 'https://ci.nodejs.org/job/node-test-commit-osx/3157/'
42+
})
43+
.reply(201)
44+
45+
t.plan(1)
46+
t.tearDown(() => scope.done())
47+
48+
supertest(app)
49+
.post('/node/jenkins')
50+
.send(fixture)
51+
.expect(201)
52+
.end((err, res) => {
53+
t.equal(err, null)
54+
})
55+
})
56+
57+
function ignoreQueryParams (pathAndQuery) {
58+
return url.parse(pathAndQuery, true).pathname
59+
}
60+
61+
function readFixture (fixtureName) {
62+
const content = fs.readFileSync(path.join(__dirname, '_fixtures', fixtureName)).toString()
63+
return JSON.parse(content)
64+
}

0 commit comments

Comments
 (0)