Skip to content

Commit

Permalink
Added a couple of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipj committed May 10, 2016
1 parent f342a05 commit d0137f3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
},
"devDependencies": {
"eventsource": "^0.2.1",
"nock": "^8.0.0",
"nodemon": "^1.9.1",
"request": "^2.72.0",
"standard": "^6.0.7",
"supertest": "^1.2.0",
"tap": "^5.7.1"
}
}
2 changes: 1 addition & 1 deletion scripts/node-jenkins-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ module.exports = function (app) {
repoName: 'node'
}, req.body)

res.end()
res.status(201).end()
})
}
62 changes: 62 additions & 0 deletions test/push-jenkins-update.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'

const tap = require('tap')
const fs = require('fs')
const path = require('path')
const url = require('url')
const nock = require('nock')
const supertest = require('supertest')

const app = require('../app')

tap.test('Sends POST requests to /repos/nodejs/node/statuses/<SHA>', (t) => {
const fixture = readFixture('success-payload.json')
const scope = nock('https://api.github.com')
.filteringPath(ignoreQueryParams)
.post('/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1')
.reply(201)

t.plan(1)
t.tearDown(() => scope.done())

supertest(app)
.post('/node/jenkins')
.send(fixture)
.expect(201)
.end((err, res) => {
t.equal(err, null)
})
})

tap.test('Forwards payload provided in incoming POST to GitHub status API', (t) => {
const fixture = readFixture('success-payload.json')
const scope = nock('https://api.github.com')
.filteringPath(ignoreQueryParams)
.post('/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1', {
state: 'success',
context: 'test/osx',
description: 'tests passed',
target_url: 'https://ci.nodejs.org/job/node-test-commit-osx/3157/'
})
.reply(201)

t.plan(1)
t.tearDown(() => scope.done())

supertest(app)
.post('/node/jenkins')
.send(fixture)
.expect(201)
.end((err, res) => {
t.equal(err, null)
})
})

function ignoreQueryParams (pathAndQuery) {
return url.parse(pathAndQuery, true).pathname
}

function readFixture (fixtureName) {
const content = fs.readFileSync(path.join(__dirname, '_fixtures', fixtureName)).toString()
return JSON.parse(content)
}

0 comments on commit d0137f3

Please sign in to comment.