Skip to content

Commit e635f28

Browse files
committed
Corrects error in filters when defaults values are use
1 parent de5f8b4 commit e635f28

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/mapper/filters.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ function normalizeDate(date, isDateStart) {
229229
}
230230

231231
function validate_filters(_values, _default) {
232-
return Object.assign(_values, _default)
232+
return {
233+
..._default, ..._values
234+
}
233235
}
234236

235237
exports = module.exports = {

test/unit/filters.spec.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,24 @@ describe('QueryString: Filters', function () {
3131
})
3232
})
3333

34-
context('when use the default options without query', function () {
34+
context('when use the default options', function () {
3535
it('should return a JSON with default filters params', function (done) {
3636
const result = filter.filters({}, default_options)
3737
expect(result).to.eql(default_options.default.filters)
3838
done()
3939
})
40+
41+
it('should return a JSON with default filters params and those of the query', function (done) {
42+
const options = {
43+
...default_options, ...{
44+
default: {filters: {age: '19', name: 'John'}}
45+
}
46+
}
47+
const result = filter.filters({age: '21'}, options)
48+
expect(result.name).to.eql(options.default.filters.name)
49+
expect(result.age).to.eql(21)
50+
done()
51+
})
4052
})
4153
})
4254

@@ -45,4 +57,4 @@ function verify(result) {
4557
expect(result).to.have.property('age')
4658
expect(result.name).to.eql('lucas')
4759
expect(result.age).to.eql(30)
48-
}
60+
}

0 commit comments

Comments
 (0)