Skip to content

Commit

Permalink
Validate response statusCode in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Nov 8, 2015
1 parent c84a2f2 commit 19b5802
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions test/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('file', function () {

server.inject('/file', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
done();
});
Expand All @@ -83,6 +84,7 @@ describe('file', function () {

server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -98,6 +100,7 @@ describe('file', function () {

server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -113,6 +116,7 @@ describe('file', function () {

server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -128,6 +132,7 @@ describe('file', function () {

server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -143,6 +148,7 @@ describe('file', function () {

server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -158,6 +164,7 @@ describe('file', function () {

server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -178,6 +185,7 @@ describe('file', function () {

server.inject('/file', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -198,6 +206,7 @@ describe('file', function () {

server.inject('/file', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -218,6 +227,7 @@ describe('file', function () {

server.inject('/file', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -238,6 +248,7 @@ describe('file', function () {

server.inject('/file', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand Down Expand Up @@ -272,21 +283,22 @@ describe('file', function () {
});
});

it('returns a file using the build-in handler config', function (done) {
it('returns a file using the built-in handler config', function (done) {

var server = provisionServer({ routes: { files: { relativeTo: __dirname } } });
server.route({ method: 'GET', path: '/staticfile', handler: { file: Path.join(__dirname, '..', 'package.json') } });

server.inject('/staticfile', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
done();
});
});

it('returns a file using the file function with the build-in handler config', function (done) {
it('returns a file using the file function with the built-in handler config', function (done) {

var filenameFn = function (request) {

Expand All @@ -298,6 +310,7 @@ describe('file', function () {

server.inject('/filefn/index.js', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('// Load modules');
expect(res.headers['content-type']).to.equal('application/javascript; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -317,6 +330,7 @@ describe('file', function () {

server.inject('/relativefile', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -331,6 +345,7 @@ describe('file', function () {

server.inject('/relativestaticfile', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('hapi');
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-length']).to.exist();
Expand All @@ -345,6 +360,7 @@ describe('file', function () {

server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('application/octet-stream');
done();
});
Expand All @@ -362,6 +378,7 @@ describe('file', function () {

server.inject('/file', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('application/example');
done();
});
Expand Down Expand Up @@ -858,6 +875,7 @@ describe('file', function () {

server.inject({ url: '/file', headers: { 'accept-encoding': 'gzip' } }, function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-encoding']).to.equal('gzip');
expect(res.headers['content-length']).to.not.exist();
Expand All @@ -878,6 +896,7 @@ describe('file', function () {

server.inject({ url: '/file', headers: { 'accept-encoding': 'gzip' } }, function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('image/png');
expect(res.headers['content-encoding']).to.not.exist();
expect(res.headers['content-length']).to.equal(42010);
Expand All @@ -898,6 +917,7 @@ describe('file', function () {

server.inject({ url: '/file', headers: { 'accept-encoding': 'deflate' } }, function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('application/json; charset=utf-8');
expect(res.headers['content-encoding']).to.equal('deflate');
expect(res.headers['content-length']).to.not.exist();
Expand All @@ -915,6 +935,7 @@ describe('file', function () {

server.inject({ url: '/file', headers: { 'accept-encoding': 'gzip' } }, function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('image/png');
expect(res.headers['content-encoding']).to.equal('gzip');
expect(res.headers['content-length']).to.equal(content.length);
Expand All @@ -930,6 +951,7 @@ describe('file', function () {

server.inject({ url: '/file', headers: { 'accept-encoding': 'gzip' } }, function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-encoding']).to.equal('gzip');
expect(res.headers['content-length']).to.not.exist();
expect(res.payload).to.exist();
Expand Down Expand Up @@ -959,6 +981,7 @@ describe('file', function () {

server.inject('/file', function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('image/png');
expect(res.headers['content-encoding']).to.not.exist();
expect(res.payload).to.exist();
Expand All @@ -973,6 +996,7 @@ describe('file', function () {

server.inject({ url: '/file', headers: { 'accept-encoding': 'gzip' } }, function (res) {

expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('image/png');
expect(res.headers['content-encoding']).to.not.exist();
expect(res.payload).to.exist();
Expand Down

0 comments on commit 19b5802

Please sign in to comment.