adding test

main
HerrHase 2 years ago
parent a433b70b9b
commit cb910b3f18

@ -1,10 +1,31 @@
/**
*
*
*
*/
class Filter { class Filter {
/**
*
*
* @param {object} options
*
*/
constructor(options) { constructor(options) {
this._options = options this._options = options
} }
/**
* if result with key is equal
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_eq(value, key, result) { _eq(value, key, result) {
let isValid = false let isValid = false
@ -15,6 +36,17 @@ class Filter {
return isValid return isValid
} }
/**
* if result with key is not equal
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_neq(value, key, result) { _neq(value, key, result) {
let isValid = false let isValid = false
@ -25,6 +57,18 @@ class Filter {
return isValid return isValid
} }
/**
* if result with key has a single value or
* value from value
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_in(value, key, result) { _in(value, key, result) {
let isValid = false let isValid = false
@ -55,7 +99,137 @@ class Filter {
} }
/** /**
* if result with key is lesser
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_lt(value, key, result) {
let isValid = false
if (result[key] > value) {
isValid = true
}
return isValid
}
/**
* if result with key is lesser or equal
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_lte(value, key, result) {
let isValid = false
if (result[key] >= value) {
isValid = true
}
return isValid
}
/**
* if result with key is greater
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_gt(value, key, result) {
let isValid = false
if (result[key] < value) {
isValid = true
}
return isValid
}
/**
* if result with key is greater or equal
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_gte(value, key, result) {
let isValid = false
if (result[key] <= value) {
isValid = true
}
return isValid
}
/**
* if result with key is null
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_null(value, key, result) {
let isValid = false
if (!result[key]) {
isValid = true
}
return isValid
}
/**
* if result with key is not null
*
*
* @param {object} value
* @param {string} key
* @param {object} result
*
* @return {boolean}
*
*/
_nnull(value, key, result) {
let isValid = false
if (result[key]) {
isValid = true
}
return isValid
}
/**
* run through all options with single result
*
* *
* @param {object} result
* @return {boolean}
* *
*/ */
validate(result) { validate(result) {

@ -72,4 +72,94 @@ describe('Filter', function () {
assert.equal(filter.validate(data), true) assert.equal(filter.validate(data), true)
}) })
it('_lt', function() {
const filter = new Filter({
number: {
_lt: 100
}
})
const data = {
number: 150
}
assert.equal(filter.validate(data), true)
})
it('_lte', function() {
const filter = new Filter({
number: {
_lte: 150
}
})
const data = {
number: 150
}
assert.equal(filter.validate(data), true)
})
it('_gt', function() {
const filter = new Filter({
number: {
_gt: 150
}
})
const data = {
number: 100
}
assert.equal(filter.validate(data), true)
})
it('_gte', function() {
const filter = new Filter({
number: {
_gte: 150
}
})
const data = {
number: 100
}
assert.equal(filter.validate(data), true)
})
it('_null', function() {
const filter = new Filter({
not: {
_null: true
}
})
const data = {
}
assert.equal(filter.validate(data), true)
})
it('_nnull', function() {
const filter = new Filter({
not: {
_nnull: true
}
})
const data = {
not: true
}
assert.equal(filter.validate(data), true)
})
}) })

Loading…
Cancel
Save