Files
probot/test/server.test.js
Brandon Keepers 1e2551853e feat: Add request/response logging (#322)
BREAKING CHANGE:
- Default log level is now `INFO` instead of `DEBUG`
2017-11-25 22:16:54 -06:00

38 lines
994 B
JavaScript

const request = require('supertest')
const createServer = require('../lib/server')
const logger = require('../lib/logger')
describe('server', function () {
let server
let webhook
beforeEach(() => {
webhook = jest.fn((req, res, next) => next())
server = createServer({webhook, logger})
// Error handler to avoid printing logs
server.use(function (err, req, res, next) {
res.status(500).send(err.message)
})
})
describe('GET /ping', () => {
it('returns a 200 response', () => {
return request(server).get('/ping').expect(200, 'PONG')
})
})
describe('webhook handler', () => {
it('should 500 on a webhook error', () => {
webhook.mockImplementation((req, res, callback) => callback(new Error('webhook error')))
return request(server).post('/').expect(500)
})
})
describe('with an unknown url', () => {
it('responds with 404', () => {
return request(server).get('/lolnotfound').expect(404)
})
})
})