This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
crispy-train/test/integration/index_test.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-01-25 09:19:28 -05:00
'use strict';
2016-02-18 21:50:45 -05:00
const testBase = require('../test-base');
const expect = testBase.expect;
const supertest = require('supertest');
2016-01-25 09:19:28 -05:00
let server = supertest.agent('http://localhost:3000');
2016-02-18 21:50:45 -05:00
suite('Example integration tests', () => {
2016-01-25 09:19:28 -05:00
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' },
},
});
2016-02-18 21:50:45 -05:00
return done(err);
2016-01-25 09:19:28 -05:00
});
});
test('404 page works as expected', (done) => {
server.get('/foo')
.expect('Content-type', /json/)
.end((err, res) => {
expect(res.status).to.equal(404);
2016-02-18 21:50:45 -05:00
expect(res.body.status).to.equal(String(res.status));
2016-01-25 09:19:28 -05:00
expect(res.body.message).to.be.ok;
let expected = {
2016-02-18 21:50:45 -05:00
status: '404',
2016-01-25 09:19:28 -05:00
message: 'Not Found',
};
if (process.env.NODE_ENV === 'development') {
expected.error = {
2016-02-18 21:50:45 -05:00
code: '404',
status: '404',
name: 'Http404Error',
message: 'Not Found',
2016-01-25 09:19:28 -05:00
};
}
expect(res.body).to.deep.equal(expected);
2016-02-18 21:50:45 -05:00
return done(err);
2016-01-25 09:19:28 -05:00
});
});
});