Skip to content

Commit

Permalink
updated test file to fat arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
daanvanham committed Jun 24, 2016
1 parent adc746b commit 234d69a
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
'use strict';

var Lab = require('lab'),
const Lab = require('lab'),
lab = exports.lab = Lab.script(),
Code = require('code'),
status = require('../lib');

function Reply() {
var reply = this;
let reply = this;

reply.headers = {};

reply.code = function code(statusCode) {
reply.code = (statusCode) => {
reply.statusCode = statusCode;
return reply;
};

reply.type = function type(contentType) {
reply.type = (contentType) => {
reply.header('Content-Type', contentType);

return reply;
};

reply.header = function(key, value) {
reply.header = (key, value) => {
reply.headers[key] = value;

return reply;
};

return function body(result) {
return (result) => {
reply.result = result;

return reply;
};
}

Object.keys(status).forEach(function(key) {
lab.experiment(key, function() {
lab.test('should serve the right statusCode', function(done) {
var response = status[key].apply(null, [new Reply()]);
Object.keys(status).forEach((key) => {
lab.experiment(key, () => {
lab.test('should serve the right statusCode', (done) => {
let response = status[key].apply(null, [new Reply()]);

Code.expect(response.result.statusCode).to.equal(response.statusCode);

done();
});

lab.test('should contain the right key', function(done) {
var response = status[key].apply(null, [new Reply(), 'test']).result;
lab.test('should contain the right key', (done) => {
let response = status[key].apply(null, [new Reply(), 'test']).result;

if (Math.floor(response.statusCode * 0.01) >= 4) {
if (+(response.statusCode + '')[0] >= 4) {
Code.expect('error' in response).to.equal(true);
Code.expect('result' in response).to.equal(false);
}
Expand All @@ -59,17 +59,17 @@ Object.keys(status).forEach(function(key) {
done();
});

lab.test('should be able to add headers', function(done) {
var response = status[key].apply(null, [new Reply(), 'test', {'Cache-Control': 'max-age=0, no-cache, no-store'}]);
lab.test('should be able to add headers', (done) => {
let response = status[key].apply(null, [new Reply(), 'test', {'Cache-Control': 'max-age=0, no-cache, no-store'}]);

Code.expect('Cache-Control' in response.headers).to.equal(true);
Code.expect(response.headers['Cache-Control']).to.equal('max-age=0, no-cache, no-store');

done();
});

lab.test('should serve the right content type', function(done) {
var response = status[key].apply(null, [new Reply(), '<h1>Test</h1>', {'content-type': 'text/html'}]);
lab.test('should serve the right content type', (done) => {
let response = status[key].apply(null, [new Reply(), '<h1>Test</h1>', {'content-type': 'text/html'}]);

Code.expect(response.headers['content-type']).to.equal('text/html');
Code.expect(response.result).to.equal('<h1>Test</h1>');
Expand All @@ -79,9 +79,9 @@ Object.keys(status).forEach(function(key) {
});
});

lab.experiment('add a new delegation', function() {
lab.test('should be skipped if it\'s not a function', function(done) {
var response;
lab.experiment('add a new delegation', () => {
lab.test('should be skipped if it\'s not a function', (done) => {
let response;

status.addDelegation('textHtml', 'some-text');

Expand All @@ -92,12 +92,10 @@ lab.experiment('add a new delegation', function() {
done();
});

lab.test('should be able to alter the response.result', function(done) {
var response;
lab.test('should be able to alter the response.result', (done) => {
let response;

status.addDelegation('textHtml', function() {
return 'Hi!';
});
status.addDelegation('textHtml', () => 'Hi!');

response = status.ok.apply(null, [new Reply(), 'Test', {'content-type': 'text/html'}]);

Expand All @@ -106,18 +104,16 @@ lab.experiment('add a new delegation', function() {
done();
});

lab.test('should be able to alter an existing delegate', function(done) {
var response;
lab.test('should be able to alter an existing delegate', (done) => {
let response;

response = status.ok.apply(null, [new Reply(), ['Test']]);

Code.expect(response.result).to.be.an.object();
Code.expect(response.result.statusCode).to.be.a.number();
Code.expect(response.result.result).to.be.an.array();

status.addDelegation('applicationJson', function(result) {
return result;
});
status.addDelegation('applicationJson', (result) => result);

response = status.ok.apply(null, [new Reply(), ['Test']]);

Expand Down

0 comments on commit 234d69a

Please sign in to comment.