53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const testBase = require('../test-base');
|
|
const expect = testBase.expect;
|
|
const supertest = require('supertest');
|
|
|
|
let server = supertest.agent('http://localhost:3000');
|
|
|
|
suite('Example integration tests', () => {
|
|
test('Index page works as expected', (done) => {
|
|
server.get('/')
|
|
.expect('Content-type', /json/)
|
|
.expect(200)
|
|
.end((err, res) => {
|
|
expect(res.status).to.equal(200);
|
|
expect(res.body.error).to.be.undefined;
|
|
expect(res.body).to.deep.equal({
|
|
status: 200,
|
|
data: {
|
|
index: { title: 'Express' },
|
|
},
|
|
});
|
|
return done(err);
|
|
});
|
|
});
|
|
test('404 page works as expected', (done) => {
|
|
server.get('/foo')
|
|
.expect('Content-type', /json/)
|
|
.end((err, res) => {
|
|
expect(res.status).to.equal(404);
|
|
expect(res.body.status).to.equal(String(res.status));
|
|
expect(res.body.message).to.be.ok;
|
|
|
|
let expected = {
|
|
status: '404',
|
|
message: 'Not Found',
|
|
};
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
expected.error = {
|
|
code: '404',
|
|
status: '404',
|
|
name: 'Http404Error',
|
|
message: 'Not Found',
|
|
};
|
|
}
|
|
|
|
expect(res.body).to.deep.equal(expected);
|
|
|
|
return done(err);
|
|
});
|
|
});
|
|
}); |