I have the following test using Mocha, Supertest and Chai:
const app = require('../server')
const expect = require('chai').should()
const request = require('supertest')
describe('GET /webhook', function () {
context('a verify request from Facebook with a correct token', function() {
it('responds with 200 and displays the challenge query in the response body', function() {
request(app)
.get('/webhook?hub.mode=subscribe&hub.challenge=123456789&hub.verify_token=' + process.env.FB_VERIFY_TOKEN)
.expect(200)
.end(function (err, res) {
console.log(res.text)
res.should.have.property("text", "abc")
done()
})
})
})
})
As you can see, we're expecting the response to have a property 'text' with the content of 'abc'. However, when I run the tests it passes without any problems.
Here is a shortened version of the response:
ClientRequest{
res:IncomingMessage {
headers:{
'x-powered-by':'Express',
'content-type':'text/html; charset=utf-8',
'content-length':'9',
etag:'W/"9-JfnnlDI7RTiF9RgfG2JNCw"',
date:'Mon, 27 Feb 2017 19:45:30 GMT',
connection:'close'
},
rawHeaders:[
'X-Powered-By',
'Express',
'Content-Type',
'text/html; charset=utf-8',
'Content-Length',
'9',
'ETag',
'W/"9-JfnnlDI7RTiF9RgfG2JNCw"',
'Date',
'Mon, 27 Feb 2017 19:45:30 GMT',
'Connection',
'close'
],
upgrade:false,
url:'',
method:null,
statusCode:200,
statusMessage:'OK',
req:[
Circular
],
text:'123456789',
}
}
I'm expecting the test to fail, as abc != 123456789, but unfortunately this isn't the case.
Does anyone have any ideas?