Skip to content

Commit

Permalink
Use xo es6 configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby committed Sep 15, 2015
1 parent 5906702 commit 953bd9e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 66 deletions.
6 changes: 2 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"extends": "xo-space",
"extends": "xo-space/esnext",
"rules": {
"strict": [2, "global"],
"no-var": 2,
"prefer-arrow-callback": 2
"strict": [2, "global"]
},
"ecmaFeatures": {
"arrowFunctions": true,
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/indexes/{name}.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {

index.insert(req.payload)
.then(o => {
reply(o).created(req.path + '/' + o.objectID);
reply(o).created(`${req.path}/${o.objectID}`);
}, reply.error.bind(reply));
}
};
4 changes: 2 additions & 2 deletions lib/search/query_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const buildTermFilter = function (filterParams) {
// Can't currenlty be a 1 liner due to https://github.com/nodejs/node/issues/2507
const term = {[filterParams.field]: filterParams.term};
return {term: term};
return {term};
};

const buildRangeFilter = function (filterParams) {
Expand All @@ -15,7 +15,7 @@ const buildRangeFilter = function (filterParams) {
range[filterParams.field].lte = filterParams.range.to;
}

return {range: range};
return {range};
};

const buildFilter = function (filterParams) {
Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports.register = function (server, options, next) {
path: '/version',
config: {
description: 'Returns the version of the server',
handler: function (request, reply) {
handler(request, reply) {
reply(versionResponse);
}
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
"swaggerize-hapi": "^1.0.0"
},
"devDependencies": {
"babel-eslint": "^4.1.2",
"chai": "^3.2.0",
"cuid": "^1.3.8",
"enjoi": "^1.0.0",
"eslint": "^1.3.1",
"eslint-config-xo-space": "^0.4.0",
"eslint-plugin-babel": "^2.1.1",
"grunt": "^0.4.5",
"grunt-contrib-watch": "^0.6.1",
"grunt-eslint": "^17.1.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/indexes_{name}.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const specRequest = require('./spec_request');
const expect = require('chai').expect;

describe('/indexes/{name}', () => {
const testIndexName = 'test_index_' + cuid();
const testIndexName = `test_index_${cuid()}`;
const testObject = {name: 'object', field: 'value'};
let createResponse;

Expand Down
108 changes: 54 additions & 54 deletions spec/indexes_{name}_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const specRequest = require('./spec_request');
const expect = require('chai').expect;

describe('/indexes/{name}/query', () => {
const testIndexName = 'test_index_' + cuid();
const testIndexName = `test_index_${cuid()}`;
const testIndexType = 'test_type';
const document1 = {sku: '12345', price: 1};
const document2 = {sku: '98765', price: 5};
Expand All @@ -32,7 +32,7 @@ describe('/indexes/{name}/query', () => {
it('queries by keyword', () => {
const payload = {query: '12345'};

return specRequest({url: `/1/indexes/${testIndexName}/query`, method: 'post', payload: payload})
return specRequest({url: `/1/indexes/${testIndexName}/query`, method: 'post', payload})
.then(response => {
expect(response.result).to.be.deep.equal([document1]);
expect(response.statusCode).to.equal(200);
Expand All @@ -42,7 +42,7 @@ describe('/indexes/{name}/query', () => {
it('filters results by terms', () => {
const payload = {filters: [{field: 'sku', term: '12345'}]};

return specRequest({url: `/1/indexes/${testIndexName}/query`, method: 'post', payload: payload})
return specRequest({url: `/1/indexes/${testIndexName}/query`, method: 'post', payload})
.then(response => {
expect(response.result).to.be.deep.equal([document1]);
expect(response.statusCode).to.equal(200);
Expand All @@ -52,63 +52,63 @@ describe('/indexes/{name}/query', () => {
it('filters results by ranges', () => {
const payload = {filters: [{field: 'sku', range: {from: 2}}]};

return specRequest({url: `/1/indexes/${testIndexName}/query`, method: 'post', payload: payload})
return specRequest({url: `/1/indexes/${testIndexName}/query`, method: 'post', payload})
.then(response => {
expect(response.result).to.be.deep.equal([document2]);
expect(response.statusCode).to.equal(200);
});
});
});

describe('validation', () => {
it('ensures query is a string', () => {
const payload = {query: {}};

return specRequest({url: `/1/indexes/test-index/query`, method: 'post', payload: payload})
.then(response => {
expect(response.result.message).to.match(/"query" must be a string]/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures filters is an array', () => {
const payload = {filters: {}};

return specRequest({url: `/1/indexes/test-index/query`, method: 'post', payload: payload})
.then(response => {
expect(response.result.message).to.match(/"filters" must be an array]/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures filter has field', () => {
const payload = {filters: [{term: '12345'}]};

return specRequest({url: `/1/indexes/test-index/query`, method: 'post', payload: payload})
.then(response => {
expect(response.result.message).to.match(/"field" is required]/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures filter has term or range', () => {
const payload = {filters: [{field: 'sku'}]};

return specRequest({url: `/1/indexes/test-index/query`, method: 'post', payload: payload})
.then(response => {
expect(response.result.message).to.match(/"0" must have at least 2 children/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures range filter has at least 1 bound', () => {
const payload = {filters: [{field: 'sku', range: {}}]};

return specRequest({url: `/1/indexes/test-index/query`, method: 'post', payload: payload})
.then(response => {
expect(response.result.message).to.match(/"range" must have at least 1 children/);
expect(response.statusCode).to.equal(400);
});
describe('validation', () => {
it('ensures query is a string', () => {
const payload = {query: {}};

return specRequest({url: '/1/indexes/test-index/query', method: 'post', payload})
.then(response => {
expect(response.result.message).to.match(/"query" must be a string]/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures filters is an array', () => {
const payload = {filters: {}};

return specRequest({url: '/1/indexes/test-index/query', method: 'post', payload})
.then(response => {
expect(response.result.message).to.match(/"filters" must be an array]/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures filter has field', () => {
const payload = {filters: [{term: '12345'}]};

return specRequest({url: '/1/indexes/test-index/query', method: 'post', payload})
.then(response => {
expect(response.result.message).to.match(/"field" is required]/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures filter has term or range', () => {
const payload = {filters: [{field: 'sku'}]};

return specRequest({url: '/1/indexes/test-index/query', method: 'post', payload})
.then(response => {
expect(response.result.message).to.match(/"0" must have at least 2 children/);
expect(response.statusCode).to.equal(400);
});
});

it('ensures range filter has at least 1 bound', () => {
const payload = {filters: [{field: 'sku', range: {}}]};

return specRequest({url: `/1/indexes/test-index/query`, method: 'post', payload})
.then(response => {
expect(response.result.message).to.match(/"range" must have at least 1 children/);
expect(response.statusCode).to.equal(400);
});
});
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions spec/indexes_{name}_{objectID}.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const specRequest = require('./spec_request');
const expect = require('chai').expect;

describe('/indexes/{name}/{objectID}', () => {
const testIndexName = 'test_index_' + cuid();
const testIndexName = `test_index_${cuid()}`;
let indexedObject;

before(() => {
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('/indexes/{name}/{objectID}', () => {
});

it('returns a 404 when the index does not contain the identified object', () => {
return specRequest({url: '/1/indexes/' + testIndexName + '/12345'})
return specRequest({url: `/1/indexes/${testIndexName}/12345`})
.then(response => {
expect(response.statusCode).to.equal(404);
expect(response.result.message).to.equal('Index does not contain object with identifier 12345');
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (options) {
}

const apiBasePath = swagger.basePath || '';
const route = response.request.route.path.replace(new RegExp('^' + apiBasePath), '');
const route = response.request.route.path.replace(new RegExp(`^${apiBasePath}`), '');
const method = response.request.method;

const swaggerPath = swagger.paths[route];
Expand Down

0 comments on commit 953bd9e

Please sign in to comment.