From 4b482fa7d4af60d68d28378cb7574330ee13bac7 Mon Sep 17 00:00:00 2001 From: jeffsampaio Date: Fri, 3 Dec 2021 11:18:04 -0300 Subject: [PATCH] Adjustments for hotfix of version 2.1.10 - Adding accents on uppercase vowels to the search filter; - Updating dependencies. --- lib/mapper/filters.js | 13 ++- package.json | 6 +- test/integration/index.default.config.spec.js | 94 +++++++++---------- test/unit/fields.spec.js | 16 ++-- test/unit/filters.spec.js | 12 +-- test/unit/index.spec.js | 34 +++---- test/unit/ordination.spec.js | 18 ++-- test/unit/pagination.spec.js | 26 ++--- 8 files changed, 112 insertions(+), 107 deletions(-) diff --git a/lib/mapper/filters.js b/lib/mapper/filters.js index d434fb4..5bf155c 100644 --- a/lib/mapper/filters.js +++ b/lib/mapper/filters.js @@ -92,10 +92,15 @@ function buildRegEx(value) { function addAccentsRegex(string) { return string.replace(/a/g, '[a,á,à,ä,â,ã]') - .replace(/e/g, '[e,é,ë,ê]') - .replace(/i/g, '[i,í,ï]') - .replace(/o/g, '[o,ó,ö,ò,ô]') - .replace(/u/g, '[u,ü,ú,ù]') + .replace(/A/g, '[A,Á,À,Ä,Â,Ã]') + .replace(/e/g, '[e,é,ë,ê]') + .replace(/E/g, '[E,É,Ë,Ê]') + .replace(/i/g, '[i,í,ï]') + .replace(/I/g, '[I,Í,Ï]') + .replace(/o/g, '[o,ó,ö,ò,ô]') + .replace(/O/g, '[O,Ó,Ö,Ò,Ô]') + .replace(/u/g, '[u,ü,ú,ù]') + .replace(/U/g, '[U,Ü,Ú,Ù]') } function parseDate(query, options) { diff --git a/package.json b/package.json index 62998cf..59c0673 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "query-strings-parser", - "version": "2.1.9", + "version": "2.1.10", "description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...", "license": "MIT", "main": "index.js", @@ -47,8 +47,8 @@ "devDependencies": { "chai": "^4.3.4", "express": "^4.17.1", - "mocha": "^9.0.3", + "mocha": "^9.1.3", "nyc": "^15.1.0", - "supertest": "^6.1.4" + "supertest": "^6.1.6" } } diff --git a/test/integration/index.default.config.spec.js b/test/integration/index.default.config.spec.js index 8283b76..f89ff6b 100644 --- a/test/integration/index.default.config.spec.js +++ b/test/integration/index.default.config.spec.js @@ -42,7 +42,7 @@ describe('queryFilter()', function () { context('when query contains pagination param with string limit as skip', function () { it('should return req.query with set pagination params', function () { - const expect_pagination = {limit: Number.MAX_SAFE_INTEGER, skip: 2} + const expect_pagination = { limit: Number.MAX_SAFE_INTEGER, skip: 2 } const options = JSON.parse(JSON.stringify(default_options)) options.default.pagination.limit = expect_pagination.limit @@ -60,7 +60,7 @@ describe('queryFilter()', function () { context('when query contains pagination param with string skip', function () { it('should return req.query with set pagination params', function () { - const expect_pagination = {limit: 10, skip: 0} + const expect_pagination = { limit: 10, skip: 0 } const options = JSON.parse(JSON.stringify(default_options)) options.default.pagination.limit = expect_pagination.limit @@ -78,7 +78,7 @@ describe('queryFilter()', function () { context('when query contains ordination param', function () { it('should return req.query with set ordination params', function () { - const expect_sort = {name: 1, age: -1} + const expect_sort = { name: 1, age: -1 } const options = JSON.parse(JSON.stringify(default_options)) options.default.sort = expect_sort @@ -95,7 +95,7 @@ describe('queryFilter()', function () { context('when query contains fields param', function () { it('should return req.query with set field params', function () { - const expect_fields = {name: 1, age: 1} + const expect_fields = { name: 1, age: 1 } const options = JSON.parse(JSON.stringify(default_options)) options.default.fields = expect_fields @@ -112,7 +112,7 @@ describe('queryFilter()', function () { context('when query contains simple filters param', function () { it('should return req.query with set field params', function () { - const expect_filters = {name: 'lucas', age: 30} + const expect_filters = { name: 'lucas', age: 30 } const options = JSON.parse(JSON.stringify(default_options)) options.default.filters = expect_filters @@ -138,17 +138,17 @@ describe('queryFilter()', function () { name: { '$options': 'i', '$regex': 'd[o,ó,ö,ò,ô][u,ü,ú,ù]gl[a,á,à,ä,â,ã]s$' } }, { - name: { '$options': 'i', '$regex': 'j[o,ó,ö,ò,ô]rg[e,é,ë,ê]' } + name: { '$options': 'i', '$regex': 'J[O,Ó,Ö,Ò,Ô]RG[E,É,Ë,Ê]' } }], 'school.name': 'UEPB', 'timestamp': '2018-12-05T00:00:00', - '$or': [{job: 'Developer'}, {job: 'Engineer'}] + '$or': [{ job: 'Developer' }, { job: 'Engineer' }] } const options = JSON.parse(JSON.stringify(default_options)) options.default.filters = expect_filters - const query = '?name=lucas****&name=*****douglas&name=*****jorge*****&.school.name.=UEPB' + const query = '?name=lucas****&name=*****douglas&name=*****JORGE*****&.school.name.=UEPB' .concat('×tamp=2018-12-05&job=Developer,Engineer') return request(app) @@ -163,9 +163,9 @@ describe('queryFilter()', function () { it('should return req.query with set field params', function () { const expect_filters = { name: 'lucas', - age: {$gt: 30}, - timestamp: {$gt: '2018-12-05T00:00:00'}, - created_at: {$lte: '2018-12-06T00:00:00'}, + age: { $gt: 30 }, + timestamp: { $gt: '2018-12-05T00:00:00' }, + created_at: { $lte: '2018-12-06T00:00:00' }, sleep_hour: '22:40' } @@ -185,10 +185,10 @@ describe('queryFilter()', function () { it('should return req.query with set field params (with $ne filter)', function () { const expect_filters = { name: 'lucas', - age: {$gt: 30}, - type: {$ne: 'admin'}, - timestamp: {$gt: '2018-12-05T00:00:00'}, - created_at: {$lte: '2018-12-06T00:00:00'}, + age: { $gt: 30 }, + type: { $ne: 'admin' }, + timestamp: { $gt: '2018-12-05T00:00:00' }, + created_at: { $lte: '2018-12-06T00:00:00' }, sleep_hour: '22:40' } @@ -210,8 +210,8 @@ describe('queryFilter()', function () { it('should return req.query with set start_at params as today', function () { const expect_filters = { $and: [ - {created_at: {$lt: normalizeDate(dateToString(new Date()), false)}}, - {created_at: {$gte: normalizeDate(dateToString(new Date()), true)}} + { created_at: { $lt: normalizeDate(dateToString(new Date()), false) } }, + { created_at: { $gte: normalizeDate(dateToString(new Date()), true) } } ] } @@ -230,8 +230,8 @@ describe('queryFilter()', function () { it('should return req.query with set end_at params as today', function () { const expect_filters = { $and: [ - {created_at: {$lt: normalizeDate(dateToString(new Date()), false)}}, - {created_at: {$gte: '2019-02-05T00:00:00'}} + { created_at: { $lt: normalizeDate(dateToString(new Date()), false) } }, + { created_at: { $gte: '2019-02-05T00:00:00' } } ] } @@ -250,8 +250,8 @@ describe('queryFilter()', function () { it('should return req.query with set start_at params as date', function () { const expect_filters = { $and: [ - {created_at: {$lt: normalizeDate(dateToString(new Date()), false)}}, - {created_at: {$gte: '2018-12-05T00:00:01'}} + { created_at: { $lt: normalizeDate(dateToString(new Date()), false) } }, + { created_at: { $gte: '2018-12-05T00:00:01' } } ] } @@ -271,8 +271,8 @@ describe('queryFilter()', function () { it('should return req.query with set start_at params as dateTime', function () { const expect_filters = { $and: [ - {created_at: {$lt: normalizeDate(dateToString(new Date()), false)}}, - {created_at: {$gte: '2018-12-05T00:00:00'}} + { created_at: { $lt: normalizeDate(dateToString(new Date()), false) } }, + { created_at: { $gte: '2018-12-05T00:00:00' } } ] } @@ -292,8 +292,8 @@ describe('queryFilter()', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2018-12-11T00:00:00'}}, - {created_at: {$gte: '2018-12-01T00:00:00'}}] + { created_at: { $lt: '2018-12-11T00:00:00' } }, + { created_at: { $gte: '2018-12-01T00:00:00' } }] } @@ -313,8 +313,8 @@ describe('queryFilter()', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2018-12-11T03:02:01'}}, - {created_at: {$gte: '2018-12-01T01:02:03'}}] + { created_at: { $lt: '2018-12-11T03:02:01' } }, + { created_at: { $gte: '2018-12-01T01:02:03' } }] } const options = JSON.parse(JSON.stringify(default_options)) @@ -332,8 +332,8 @@ describe('queryFilter()', function () { it('should return req.query with period as day and start_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-01-26T23:59:59'}}, - {created_at: {$gte: '2019-01-24T00:00:00'}} + { created_at: { $lt: '2019-01-26T23:59:59' } }, + { created_at: { $gte: '2019-01-24T00:00:00' } } ] } @@ -352,8 +352,8 @@ describe('queryFilter()', function () { it('should return req.query with period as day and end_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-01-26T00:00:00'}}, - {created_at: {$gte: '2019-01-24T00:00:00'}} + { created_at: { $lt: '2019-01-26T00:00:00' } }, + { created_at: { $gte: '2019-01-24T00:00:00' } } ] } @@ -372,8 +372,8 @@ describe('queryFilter()', function () { it('should return req.query with period as week and start_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-01-26T23:59:59'}}, - {created_at: {$gte: '2019-01-19T00:00:00'}} + { created_at: { $lt: '2019-01-26T23:59:59' } }, + { created_at: { $gte: '2019-01-19T00:00:00' } } ] } @@ -392,8 +392,8 @@ describe('queryFilter()', function () { it('should return req.query with period as week and end_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-01-26T23:59:59'}}, - {created_at: {$gte: '2019-01-19T00:00:00'}} + { created_at: { $lt: '2019-01-26T23:59:59' } }, + { created_at: { $gte: '2019-01-19T00:00:00' } } ] } @@ -412,8 +412,8 @@ describe('queryFilter()', function () { it('should return req.query with period as month and start_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-02-24T23:59:59'}}, - {created_at: {$gte: '2019-01-24T00:00:00'}} + { created_at: { $lt: '2019-02-24T23:59:59' } }, + { created_at: { $gte: '2019-01-24T00:00:00' } } ] } @@ -432,8 +432,8 @@ describe('queryFilter()', function () { it('should return req.query with period as month and end_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-01-24T23:59:59'}}, - {created_at: {$gte: '2018-12-24T00:00:00'}} + { created_at: { $lt: '2019-01-24T23:59:59' } }, + { created_at: { $gte: '2018-12-24T00:00:00' } } ] } @@ -452,8 +452,8 @@ describe('queryFilter()', function () { it('should return req.query with period as year and start_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-02-24T23:59:59'}}, - {created_at: {$gte: '2018-02-24T00:00:00'}} + { created_at: { $lt: '2019-02-24T23:59:59' } }, + { created_at: { $gte: '2018-02-24T00:00:00' } } ] } @@ -472,8 +472,8 @@ describe('queryFilter()', function () { it('should return req.query with period as year and end_at param', function () { const expect_filters = { $and: [ - {created_at: {$lt: '2019-02-24T23:59:59'}}, - {created_at: {$gte: '2018-02-24T00:00:00'}} + { created_at: { $lt: '2019-02-24T23:59:59' } }, + { created_at: { $gte: '2018-02-24T00:00:00' } } ] } @@ -492,8 +492,8 @@ describe('queryFilter()', function () { it('should return req.query with today start_at for invalid period', function () { const expect_filters = { $and: [ - {created_at: {$lt: normalizeDate(dateToString(new Date()), false)}}, - {created_at: {$gte: normalizeDate(dateToString(new Date()), true)}} + { created_at: { $lt: normalizeDate(dateToString(new Date()), false) } }, + { created_at: { $gte: normalizeDate(dateToString(new Date()), true) } } ] } @@ -512,8 +512,8 @@ describe('queryFilter()', function () { it('should return req.query with today end_at for invalid period', function () { const expect_filters = { $and: [ - {created_at: {$lt: normalizeDate(dateToString(new Date()), false)}}, - {created_at: {$gte: '2018-12-05T00:00:01'}} + { created_at: { $lt: normalizeDate(dateToString(new Date()), false) } }, + { created_at: { $gte: '2018-12-05T00:00:01' } } ] } diff --git a/test/unit/fields.spec.js b/test/unit/fields.spec.js index 8e141f8..efe3dc8 100644 --- a/test/unit/fields.spec.js +++ b/test/unit/fields.spec.js @@ -5,7 +5,7 @@ describe('QueryString: Fields', function () { context('when query fields are a simple string', function () { it('should return a JSON with field params', function (done) { - const query = {fields: 'name,age,created_at'} + const query = { fields: 'name,age,created_at' } verify(fields.fields(query, default_options)) done() }) @@ -13,7 +13,7 @@ describe('QueryString: Fields', function () { context('when query fields are an array of strings', function () { it('should return a JSON with field params', function (done) { - const query = {fields: ['name,age', 'created_at']} + const query = { fields: ['name,age', 'created_at'] } verify(fields.fields(query, default_options)) done() }) @@ -21,7 +21,7 @@ describe('QueryString: Fields', function () { context('when there are blank spaces between query fields', function () { it('should return a JSON with field params, ignoring the blank space', function (done) { - const query = {fields: ' name , name, age , created_at'} + const query = { fields: ' name , name, age , created_at' } verify(fields.fields(query, default_options)) done() }) @@ -29,7 +29,7 @@ describe('QueryString: Fields', function () { context('when there are null fields in query fields', function () { it('should return a JSON with field params, ignoring the null fields', function (done) { - const query = {fields: ',,name,,,age,,,,,created_at,,'} + const query = { fields: ',,name,,,age,,,,,created_at,,' } verify(fields.fields(query, default_options)) done() }) @@ -37,7 +37,7 @@ describe('QueryString: Fields', function () { context('when there are special characters in query fields', function () { it('should return a JSON with field params, ignoring the special characteres', function (done) { - const query = {fields: ' ,,, ^ & * ( ´) @!n@a"m "e,$%ag" e",created _a t '} + const query = { fields: ' ,,, ^ & * ( ´) @!n@a"m "e,$%ag" e",created _a t ' } verify(fields.fields(query, default_options)) done() @@ -54,7 +54,7 @@ describe('QueryString: Fields', function () { context('when use custom params', function () { it('should return a JSON with custom params', function () { - const custom_options = {default: {fields: {name: 1, age: 1, _id: 0}}} + const custom_options = { default: { fields: { name: 1, age: 1, _id: 0 } } } const result = fields.fields({}, custom_options) expect(result.name).to.eql(custom_options.default.fields.name) expect(result.age).to.eql(custom_options.default.fields.age) @@ -62,8 +62,8 @@ describe('QueryString: Fields', function () { }) it('should return a JSON with custom params and those of the query', function () { - const custom_options = {default: {fields: {name: 1, _id: 1}}} - const result = fields.fields({fields: 'age'}, custom_options) + const custom_options = { default: { fields: { name: 1, _id: 1 } } } + const result = fields.fields({ fields: 'age' }, custom_options) expect(result.name).to.eql(custom_options.default.fields.name) expect(result._id).to.eql(custom_options.default.fields._id) expect(result.age).to.eql(1) diff --git a/test/unit/filters.spec.js b/test/unit/filters.spec.js index b0c3cf5..e5e0695 100644 --- a/test/unit/filters.spec.js +++ b/test/unit/filters.spec.js @@ -6,7 +6,7 @@ describe('QueryString: Filters', function () { context('when query filters are string/number parameters', function () { it('should return a JSON with filters params', function (done) { - verify(filter.filters({name: 'lucas', age: '30'}, default_options)) + verify(filter.filters({ name: 'lucas', age: '30' }, default_options)) done() }) }) @@ -31,20 +31,20 @@ describe('QueryString: Filters', function () { context('when query filters its a object', function () { it('should ignore the object param and returns another filters', function () { - verify(filter.filters({job: {first: 'developer'}, name: 'lucas', age: '30'}, default_options)) + verify(filter.filters({ job: { first: 'developer' }, name: 'lucas', age: '30' }, default_options)) }) }) context('when query filters key contains blank space', function () { it('should return a JSON with filters params, ignoring blank spaces', function (done) { - verify(filter.filters({' na me ': 'lucas', age: '30'}, default_options)) + verify(filter.filters({ ' na me ': 'lucas', age: '30' }, default_options)) done() }) }) context('when query filters key contains special characters', function () { it('should return a JSON with filters params, ignoring the special characteres', function (done) { - verify(filter.filters({'#(@@$na%me!?': 'lucas', age: '30'}, default_options)) + verify(filter.filters({ '#(@@$na%me!?': 'lucas', age: '30' }, default_options)) done() }) }) @@ -59,10 +59,10 @@ describe('QueryString: Filters', function () { it('should return a JSON with default filters params and those of the query', function (done) { const options = { ...default_options, ...{ - default: {filters: {age: '19', name: 'John'}} + default: { filters: { age: '19', name: 'John' } } } } - const result = filter.filters({age: '21'}, options) + const result = filter.filters({ age: '21' }, options) expect(result.name).to.eql(options.default.filters.name) expect(result.age).to.eql(21) done() diff --git a/test/unit/index.spec.js b/test/unit/index.spec.js index 8e39e5d..ada164f 100644 --- a/test/unit/index.spec.js +++ b/test/unit/index.spec.js @@ -12,7 +12,7 @@ describe('QueryString: Parsers', function () { context('when query is passed as object', function () { it('should return parse query fields', function () { - const query = {fields: 'name,age,created_at'} + const query = { fields: 'name,age,created_at' } verifyFields(index.parseFields(query, {})) }) }) @@ -20,7 +20,7 @@ describe('QueryString: Parsers', function () { context('when use parse with default fields', function () { it('should return parse query fields merged with default fields', function () { const query = '?fields=name,age,created_at' - const parsed_params = index.parseFields(query, {_id: 0}) + const parsed_params = index.parseFields(query, { _id: 0 }) verifyFields(parsed_params) expect(parsed_params).to.have.property('_id') expect(parsed_params._id).to.eql(0) @@ -39,7 +39,7 @@ describe('QueryString: Parsers', function () { context('when query is passed as object', function () { it('should return parse query sort', function () { - const query = {sort: 'name,-age,created_at'} + const query = { sort: 'name,-age,created_at' } verifySort(index.parseSort(query, {})) }) }) @@ -47,8 +47,8 @@ describe('QueryString: Parsers', function () { context('when use parse with default sort', function () { it('should return parse query sort merged with default sort', function () { const query = '?sort=name,-age,created_at' - const parsed_params = index.parseSort(query, {_id: 'desc'}) - verifySort(index.parseSort(query, {_id: 'desc'})) + const parsed_params = index.parseSort(query, { _id: 'desc' }) + verifySort(index.parseSort(query, { _id: 'desc' })) expect(parsed_params).to.have.property('_id') expect(parsed_params._id).to.eql('desc') }) @@ -65,7 +65,7 @@ describe('QueryString: Parsers', function () { context('when query is passed as object', function () { it('should return parse query pagination', function () { - const query = {limit: '20', page: '3'} + const query = { limit: '20', page: '3' } verifyPage(index.parsePagination(query, {}, true)) }) }) @@ -73,7 +73,7 @@ describe('QueryString: Parsers', function () { context('when use parse with default pagination', function () { it('should return parse query pagination', function () { const query = '?page=3' - verifyPage(index.parsePagination(query, {limit: 20}, true)) + verifyPage(index.parsePagination(query, { limit: 20 }, true)) }) }) }) @@ -88,7 +88,7 @@ describe('QueryString: Parsers', function () { context('when query is passed as object', function () { it('should return parse query filter', function () { - const query = {name: 'lucas', age: '30'} + const query = { name: 'lucas', age: '30' } verifyFilter(index.parseFilter(query, {})) }) }) @@ -96,7 +96,7 @@ describe('QueryString: Parsers', function () { context('when use parse with default filters', function () { it('should return parse query filters merge with default filters', function () { const query = '?name=lucas&age=30' - const result = index.parseFilter(query, {'job': 'Engineer'}) + const result = index.parseFilter(query, { 'job': 'Engineer' }) verifyFilter(result) expect(result).to.have.property('job') expect(result.job).to.eql('Engineer') @@ -114,7 +114,7 @@ describe('QueryString: Parsers', function () { context('when query is passed as object', function () { it('should return parse query date', function () { - const query = {start_at: '2019-02-05T00:00:00', end_at: '2019-02-05T23:59:59'} + const query = { start_at: '2019-02-05T00:00:00', end_at: '2019-02-05T23:59:59' } verifyDate(index.parseDate(query, {})) }) }) @@ -122,7 +122,7 @@ describe('QueryString: Parsers', function () { context('when use parse with default date fields', function () { it('should return parse query date merge with default date', function () { const query = '?start_at=2019-02-05T00:00:00&end_at=2019-02-05T23:59:59' - const result = index.parseDate(query, {start_at: 'created_at', end_at: 'created_at'}) + const result = index.parseDate(query, { start_at: 'created_at', end_at: 'created_at' }) verifyDate(result) }) }) @@ -165,28 +165,28 @@ describe('QueryString: Parsers', function () { context('when parser is used with custom options', function () { it('should return parse query fields merged with default fields', function () { const query = '?fields=name,age,created_at' - const result = index.parser(query, {fields: {_id: 0}}) + const result = index.parser(query, { fields: { _id: 0 } }) verifyFields(result.fields) expect(result.fields).to.have.property('_id', 0) }) it('should return parsing query classification merged with custom classification', function () { const query = '?sort=name,-age,created_at' - const result = index.parser(query, {sort: {_id: -1}}) + const result = index.parser(query, { sort: { _id: -1 } }) expect(result.sort).to.have.property('_id', -1) }) it('should return parse query pagination', function () { const query = '?page=3' verifyPage(index.parser(query, - {pagination: {limit: 20}}, - {use_page: true} + { pagination: { limit: 20 } }, + { use_page: true } ).pagination) }) it('should return parse query filters merge with custom filters', function () { const query = '?name=lucas&age=30' - const result = index.parser(query, {filters: {'job': 'Engineer'}}) + const result = index.parser(query, { filters: { 'job': 'Engineer' } }) verifyFilter(result.filters) expect(result.filters).to.have.property('job', 'Engineer') }) @@ -196,7 +196,7 @@ describe('QueryString: Parsers', function () { const result = index.parser( query, {}, - {date_fields: {start_at: 'timestamp', end_at: 'timestamp'}}) + { date_fields: { start_at: 'timestamp', end_at: 'timestamp' } }) expect(result.filters.$and[0]).to.have.all.keys('timestamp') expect(result.filters.$and[1]).to.have.all.keys('timestamp') }) diff --git a/test/unit/ordination.spec.js b/test/unit/ordination.spec.js index 02297e2..c1a933b 100644 --- a/test/unit/ordination.spec.js +++ b/test/unit/ordination.spec.js @@ -5,14 +5,14 @@ describe('QueryString: Ordination', function () { context('when ordination query is a simple string', function () { it('should return a JSON with order params', function (done) { - verify(ordination.sort({sort: '-name,age,created_at'}, default_options)) + verify(ordination.sort({ sort: '-name,age,created_at' }, default_options)) done() }) }) context('when ordination query is a second-level string', function () { it('should return a JSON with order params', function (done) { - const result = ordination.sort({sort: '-user.age'}, default_options) + const result = ordination.sort({ sort: '-user.age' }, default_options) expect(result['user.age']).to.eql(-1) done() }) @@ -20,28 +20,28 @@ describe('QueryString: Ordination', function () { context('when ordination query is an array of strings', function () { it('should return a JSON with order params', function (done) { - verify(ordination.sort({sort: ['-name,age', 'created_at']}, default_options)) + verify(ordination.sort({ sort: ['-name,age', 'created_at'] }, default_options)) done() }) }) context('when there are blank spaces between ordination query', function () { it('should return a JSON with order params, ignoring the blank space', function (done) { - verify(ordination.sort({sort: '-na m e, age, cr eat ed_at'}, default_options)) + verify(ordination.sort({ sort: '-na m e, age, cr eat ed_at' }, default_options)) done() }) }) context('when there are null fields in ordination query', function () { it('should return a JSON with order params, ignoring the null fields', function (done) { - verify(ordination.sort({sort: ',,,,,-name,,,,age,,,created_at,,,,,,,'}, default_options)) + verify(ordination.sort({ sort: ',,,,,-name,,,,age,,,created_at,,,,,,,' }, default_options)) done() }) }) context('when there are special characters in ordination query', function () { it('should return a JSON with order params, ignoring the special characteres', function (done) { - verify(ordination.sort({sort: '-$%n@am#$e??,!!ag%e,c***r$@$eated_at'}, default_options)) + verify(ordination.sort({ sort: '-$%n@am#$e??,!!ag%e,c***r$@$eated_at' }, default_options)) done() }) @@ -58,14 +58,14 @@ describe('QueryString: Ordination', function () { context('when use custom params', function () { it('should return a JSON with custom params', function () { - const custom_options = {default: {sort: {created_at: 1}}} + const custom_options = { default: { sort: { created_at: 1 } } } const result = ordination.sort({}, custom_options) expect(result.created_at).to.eql(1) }) it('should return a JSON with custom parameters and those of the query', function () { - const custom_options = {default: {sort: {created_at: 1}}} - const result = ordination.sort({sort: '-created_at,-age,name'}, custom_options) + const custom_options = { default: { sort: { created_at: 1 } } } + const result = ordination.sort({ sort: '-created_at,-age,name' }, custom_options) expect(result.created_at).to.eql(-1) expect(result.age).to.eql(-1) expect(result.name).to.eql(1) diff --git a/test/unit/pagination.spec.js b/test/unit/pagination.spec.js index ce73bef..b4116db 100644 --- a/test/unit/pagination.spec.js +++ b/test/unit/pagination.spec.js @@ -6,7 +6,7 @@ describe('QueryString: Pagination', function () { context('when page query contains limit and page params as string', function () { it('should return a JSON with pagination fields', function (done) { default_options.use_page = true - var result = pagination.pagination({limit: '10', page: '3'}, default_options) + var result = pagination.pagination({ limit: '10', page: '3' }, default_options) verifyPage(result) expect(result.limit).to.eql(10) expect(result.page).to.eql(3) @@ -17,7 +17,7 @@ describe('QueryString: Pagination', function () { context('when page query contains limit and skip params as string', function () { it('should return a JSON with pagination fields', function (done) { default_options.use_page = false - const result = pagination.pagination({limit: '10', skip: '20'}, default_options) + const result = pagination.pagination({ limit: '10', skip: '20' }, default_options) verifySkip(result) expect(result.limit).to.eql(10) expect(result.skip).to.eql(20) @@ -28,7 +28,7 @@ describe('QueryString: Pagination', function () { context('when page query contains only page param as string', function () { it('should return a JSON with pagination fields, with limit equals 2^53-1', function (done) { default_options.use_page = true - const result = pagination.pagination({page: '3'}, default_options) + const result = pagination.pagination({ page: '3' }, default_options) verifyPage(result) expect(result.limit).to.eql(Number.MAX_SAFE_INTEGER) expect(result.page).to.eql(3) @@ -39,7 +39,7 @@ describe('QueryString: Pagination', function () { context('when page query contains only skip param as string', function () { it('should return a JSON with pagination fields, with limit equals 2^53-1', function (done) { default_options.use_page = false - const result = pagination.pagination({skip: '10'}, default_options) + const result = pagination.pagination({ skip: '10' }, default_options) verifySkip(result) expect(result.limit).to.eql(Number.MAX_SAFE_INTEGER) expect(result.skip).to.eql(10) @@ -50,7 +50,7 @@ describe('QueryString: Pagination', function () { context('when page query contains limit and page params as array', function () { it('should return a JSON with pagination fields', function (done) { default_options.use_page = true - const result = pagination.pagination({limit: ['10', '2'], page: ['3', '4']}, default_options) + const result = pagination.pagination({ limit: ['10', '2'], page: ['3', '4'] }, default_options) verifyPage(result) expect(result.limit).to.eql(10) expect(result.page).to.eql(3) @@ -61,7 +61,7 @@ describe('QueryString: Pagination', function () { context('when page query contains limit and skip params as array', function () { it('should return a JSON with pagination fields', function (done) { default_options.use_page = false - const result = pagination.pagination({limit: ['10', '2'], skip: ['20', '30']}, default_options) + const result = pagination.pagination({ limit: ['10', '2'], skip: ['20', '30'] }, default_options) verifySkip(result) expect(result.limit).to.eql(10) expect(result.skip).to.eql(20) @@ -72,7 +72,7 @@ describe('QueryString: Pagination', function () { context('when page query contains only page param as array', function () { it('should return a JSON with pagination fields, with limit equals 2^53-1', function (done) { default_options.use_page = true - const result = pagination.pagination({page: ['3', '4']}, default_options) + const result = pagination.pagination({ page: ['3', '4'] }, default_options) verifyPage(result) expect(result.limit).to.eql(Number.MAX_SAFE_INTEGER) expect(result.page).to.eql(3) @@ -83,7 +83,7 @@ describe('QueryString: Pagination', function () { context('when page query contains only skip param as array', function () { it('should return a JSON with pagination fields, with limit equals 2^53-1', function (done) { default_options.use_page = false - const result = pagination.pagination({skip: ['10', '20']}, default_options) + const result = pagination.pagination({ skip: ['10', '20'] }, default_options) verifySkip(result) expect(result.limit).to.eql(Number.MAX_SAFE_INTEGER) expect(result.skip).to.eql(10) @@ -94,7 +94,7 @@ describe('QueryString: Pagination', function () { context('when page query contains blank space in page param', function () { it('should return a JSON with pagination fields, ignoring the blank space', function (done) { default_options.use_page = true - const result = pagination.pagination({limit: '10', page: ' 3 '}, default_options) + const result = pagination.pagination({ limit: '10', page: ' 3 ' }, default_options) verifyPage(result) expect(result.limit).to.eql(10) expect(result.page).to.eql(3) @@ -105,7 +105,7 @@ describe('QueryString: Pagination', function () { context('when page query contains blank space in skip param', function () { it('should return a JSON with pagination fields, ignoring the blank space', function (done) { default_options.use_page = false - const result = pagination.pagination({limit: '10', skip: ' 20 '}, default_options) + const result = pagination.pagination({ limit: '10', skip: ' 20 ' }, default_options) verifySkip(result) expect(result.limit).to.eql(10) expect(result.skip).to.eql(20) @@ -116,7 +116,7 @@ describe('QueryString: Pagination', function () { context('when page query contains special character or letters in page param', function () { it('should return a JSON with pagination fields, ignoring the special character', function (done) { default_options.use_page = true - const result = pagination.pagination({limit: '10', page: '3$@#!@%+*&Asadas'}, default_options) + const result = pagination.pagination({ limit: '10', page: '3$@#!@%+*&Asadas' }, default_options) verifyPage(result) expect(result.limit).to.eql(10) expect(result.page).to.eql(3) @@ -127,7 +127,7 @@ describe('QueryString: Pagination', function () { context('when page query contains special character or letters in skip param', function () { it('should return a JSON with pagination fields, ignoring the special character', function (done) { default_options.use_page = false - const result = pagination.pagination({limit: '10', skip: '20$@#!@%+*&Asadas'}, default_options) + const result = pagination.pagination({ limit: '10', skip: '20$@#!@%+*&Asadas' }, default_options) verifySkip(result) expect(result.limit).to.eql(10) expect(result.skip).to.eql(20) @@ -192,7 +192,7 @@ describe('QueryString: Pagination', function () { }, use_page: true } - const result = pagination.pagination({page: '3', limit: '10'}, custom_options) + const result = pagination.pagination({ page: '3', limit: '10' }, custom_options) verifyPage(result) expect(result.limit).to.eql(10) expect(result.page).to.eql(3)