Skip to content

Commit 4589201

Browse files
committed
Merge branch 'hotfix/2.1.5'
2 parents 015bcb7 + 5c7647d commit 4589201

File tree

9 files changed

+41
-46
lines changed

9 files changed

+41
-46
lines changed

Diff for: .mocharc.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exit: true # could be expressed as "no-exit: true"
2+
recursive: true
3+
reporter: spec
4+
require:
5+
- 'test/global.js'
6+
slow: 5000
7+
timeout: 5000 # same as "no-timeout: true" or "timeout: 0"

Diff for: .travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ node_js:
77
- "10"
88
- "11"
99
- "12"
10+
- "13"
11+
- "14"
1012
sudo: false
11-
cache:
12-
directories:
13-
- node_modules
1413
before_script:
1514
- npm install && npm install coveralls mocha-lcov-reporter --save-dev
1615
script:

Diff for: README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ app.get('/', (req, res) => {
3535
* Result (req.query):
3636
* {
3737
* fields: { name: 1, age: 1 },
38-
* sort: { created_at: 'asc' }
38+
* sort: { created_at: 1 }
3939
* filters: {},
4040
* pagination: {
4141
* skip: 10,
@@ -61,7 +61,7 @@ app.use(qs({
6161
},
6262
default: {
6363
fields: {name: 1 , age: 1, number: 1, _id: 0},
64-
sort: { created_at: 'desc' },
64+
sort: { created_at: -1 },
6565
filters: {},
6666
pagination: {
6767
page: 1,
@@ -75,7 +75,7 @@ app.use(qs({
7575
* Result (req.query):
7676
* {
7777
* fields: { name: 1, age: 1},
78-
* sort: { created_at: 'desc' }
78+
* sort: { created_at: -1 }
7979
* filters: {age: 30},
8080
* pagination: {
8181
* limit: 100,
@@ -127,7 +127,7 @@ console.log(qs.parseFields(query, {}, { use_page: true }))
127127
* Result:
128128
* {
129129
* fields: { name: 1, age: 1 },
130-
* sort: { created_at: 'asc' },
130+
* sort: { created_at: 1 },
131131
* filters: {},
132132
* pagination: { limit: 10, page: 1 },
133133
* original: '?fields=name,age&page=1&limit=10&sort=created_at'
@@ -166,9 +166,9 @@ console.log(qs.parseSort(query))
166166
/**
167167
* Result:
168168
* {
169-
* name: 'asc',
170-
* age: 'desc',
171-
* created_at: 'asc'
169+
* name: 1,
170+
* age: -1,
171+
* created_at: 1
172172
* }
173173
*/
174174
```

Diff for: lib/mapper/ordination.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function processQuery(query) {
1919
query = query.replace(/([^\w\s,-])|(\s{1,})/gi, '')
2020
query.split(',').forEach(function (elem) {
2121
elem = elem.trim()
22-
if (elem[0] === '-') result[elem.substr(1)] = 'desc'
23-
else result[elem] = 'asc'
22+
if (elem[0] === '-') result[elem.substr(1)] = -1
23+
else result[elem] = 1
2424
})
2525
return result
2626
}

Diff for: package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "query-strings-parser",
3-
"version": "2.1.4",
3+
"version": "2.1.5",
44
"description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...",
55
"license": "MIT",
66
"main": "index.js",
77
"scripts": {
8-
"test": "nyc --clean --all --reporter=text-summary mocha --opts test/mocha.opts test/**/*.spec.js",
9-
"test:unit": "nyc --clean --all --reporter=text-summary mocha --opts test/mocha.opts test/unit/*.spec.js",
10-
"test:integration": "nyc --clean --all --reporter=text-summary mocha --opts test/mocha.opts test/integration/*.spec.js",
11-
"test:cov": "nyc --clean --all --reporter=html --reporter=text mocha --opts test/mocha.opts test/**/*.spec.js"
8+
"test": "nyc --clean --all --reporter=text-summary mocha test/**/*.spec.js",
9+
"test:unit": "nyc --clean --all --reporter=text-summary mocha test/unit/*.spec.js",
10+
"test:integration": "nyc --clean --all --reporter=text-summary mocha test/integration/*.spec.js",
11+
"test:cov": "nyc --clean --all --reporter=html --reporter=text mocha test/**/*.spec.js"
1212
},
1313
"directories": {
1414
"lib": "lib",
@@ -44,8 +44,8 @@
4444
"devDependencies": {
4545
"chai": "^4.2.0",
4646
"express": "^4.17.1",
47-
"mocha": "^6.2.1",
48-
"nyc": "^14.1.1",
47+
"mocha": "^7.2.0",
48+
"nyc": "^15.1.0",
4949
"supertest": "^4.0.2"
5050
}
5151
}

Diff for: test/integration/index.default.config.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('queryFilter()', function () {
7878

7979
context('when query contains ordination param', function () {
8080
it('should return req.query with set ordination params', function () {
81-
const expect_sort = {name: 'asc', age: 'desc'}
81+
const expect_sort = {name: 1, age: -1}
8282

8383
const options = JSON.parse(JSON.stringify(default_options))
8484
options.default.sort = expect_sort
@@ -88,6 +88,7 @@ describe('queryFilter()', function () {
8888
return request(app)
8989
.get(query)
9090
.then(res => {
91+
console.table(res.body)
9192
validate(res.body, options)
9293
})
9394
})

Diff for: test/mocha.opts

-6
This file was deleted.

Diff for: test/unit/index.spec.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ describe('QueryString: Parsers', function () {
172172

173173
it('should return parsing query classification merged with custom classification', function () {
174174
const query = '?sort=name,-age,created_at'
175-
const result = index.parser(query, {sort: {_id: 'desc'}})
176-
verifySort(result.sort)
177-
expect(result.sort).to.have.property('_id', 'desc')
175+
const result = index.parser(query, {sort: {_id: -1}})
176+
expect(result.sort).to.have.property('_id', -1)
178177
})
179178

180179
it('should return parse query pagination', function () {
@@ -218,9 +217,9 @@ function verifySort(result) {
218217
expect(result).to.have.property('name')
219218
expect(result).to.have.property('age')
220219
expect(result).to.have.property('created_at')
221-
expect(result.name).to.eql('asc')
222-
expect(result.age).to.eql('desc')
223-
expect(result.created_at).to.eql('asc')
220+
expect(result.name).to.eql(1)
221+
expect(result.age).to.eql(-1)
222+
expect(result.created_at).to.eql(1)
224223
}
225224

226225
function verifyPage(result) {

Diff for: test/unit/ordination.spec.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,24 @@ describe('QueryString: Ordination', function () {
5050

5151
context('when use custom params', function () {
5252
it('should return a JSON with custom params', function () {
53-
const custom_options = {default: {sort: {created_at: 'asc'}}}
53+
const custom_options = {default: {sort: {created_at: 1}}}
5454
const result = ordination.sort({}, custom_options)
55-
expect(result).is.not.null
56-
expect(result).to.have.property('created_at')
57-
expect(result.created_at).to.eql('asc')
55+
expect(result.created_at).to.eql(1)
5856
})
5957

6058
it('should return a JSON with custom parameters and those of the query', function () {
61-
const custom_options = {default: {sort: {created_at: 'asc'}}}
59+
const custom_options = {default: {sort: {created_at: 1}}}
6260
const result = ordination.sort({sort: '-created_at,-age,name'}, custom_options)
63-
expect(result.created_at).to.eql('desc')
64-
expect(result.age).to.eql('desc')
65-
expect(result.name).to.eql('asc')
61+
expect(result.created_at).to.eql(-1)
62+
expect(result.age).to.eql(-1)
63+
expect(result.name).to.eql(1)
6664
})
6765
})
6866
})
6967

7068
function verify(result) {
71-
expect(result).to.have.property('name')
72-
expect(result).to.have.property('age')
73-
expect(result).to.have.property('created_at')
74-
expect(result.name).to.eql('desc')
75-
expect(result.age).to.eql('asc')
76-
expect(result.created_at).to.eql('asc')
69+
expect(result.name).to.eql(-1)
70+
expect(result.age).to.eql(1)
71+
expect(result.created_at).to.eql(1)
7772

7873
}

0 commit comments

Comments
 (0)