@gameroom/kit
Version:
Node kit for the Gameroom API
130 lines (126 loc) • 4.85 kB
JavaScript
const { faker } = require('@faker-js/faker'),
chai = require('chai')
const {
lib: { Comparison, Filter }
} = require('../../')
const should = chai.should()
describe('Filter', () => {
describe('new Filter()', () => {
it('should create a new Filter with default values', () => {
const filter = new Filter()
should.exist(filter)
should.equal(filter.expression.comparison, 'equal_to')
should.equal(filter.expression.key, null)
should.equal(filter.expression.value, null)
})
})
describe('new Filter({ expression })', () => {
it('should create a new Filter with provided values', () => {
const comparison = '='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({ comparison, key, value })
should.exist(filter)
filter.expression.comparison.should.equal(Comparison(comparison))
filter.expression.key.should.equal(key)
filter.expression.value.should.equal(value)
})
})
describe('new Filter({ and: [] })', () => {
it('should create a new and Filter with provided values', () => {
const comparison = '>='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({ and: [{ expression: { comparison, key, value } }] })
should.exist(filter)
filter.and[0].comparison.should.equal(Comparison(comparison))
filter.and[0].key.should.equal(key)
filter.and[0].value.should.equal(value)
})
})
describe('new Filter({ and: [] })', () => {
it('should create a new and Filter with nested Filter', () => {
const comparison = '>='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({ and: [new Filter({ comparison, key, value })] })
should.exist(filter)
filter.and[0].comparison.should.equal(Comparison(comparison))
filter.and[0].key.should.equal(key)
filter.and[0].value.should.equal(value)
})
})
describe('new Filter({ and: [] })', () => {
it('should create a new and Filter with just array of objects', () => {
const comparison = '>='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({ and: [{ comparison, key, value }] })
should.exist(filter)
filter.and[0].comparison.should.equal(Comparison(comparison))
filter.and[0].key.should.equal(key)
filter.and[0].value.should.equal(value)
})
})
describe('new Filter({ or: [] })', () => {
it('should create a new or Filter with provided values', () => {
const comparison = '<='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({ or: [{ expression: { comparison, key, value } }] })
should.exist(filter)
filter.or[0].comparison.should.equal(Comparison(comparison))
filter.or[0].key.should.equal(key)
filter.or[0].value.should.equal(value)
})
})
describe('new Filter({ or: [] })', () => {
it('should create a new or Filter with nested Filter', () => {
const comparison = '>='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({ or: [new Filter({ comparison, key, value })] })
should.exist(filter)
filter.or[0].comparison.should.equal(Comparison(comparison))
filter.or[0].key.should.equal(key)
filter.or[0].value.should.equal(value)
})
})
describe('new Filter({ or: [] })', () => {
it('should create a new or Filter with just array of objects', () => {
const comparison = '>='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({ or: [{ comparison, key, value }] })
should.exist(filter)
filter.or[0].comparison.should.equal(Comparison(comparison))
filter.or[0].key.should.equal(key)
filter.or[0].value.should.equal(value)
})
})
describe('new Filter({ and: [ {}, { or:[] } ] })', () => {
it('should create a new and Filter with nested objects', () => {
const comparison = '>='
const key = faker.random.word()
const value = faker.random.word()
const filter = new Filter({
and: [
{ comparison, key, value },
{
or: [
{ comparison, key, value },
{ comparison, key, value }
]
}
]
})
should.exist(filter)
filter.and[0].comparison.should.equal(Comparison(comparison))
filter.and[0].key.should.equal(key)
filter.and[0].value.should.equal(value)
filter.and[1].or[0].comparison.should.equal(Comparison(comparison))
filter.and[1].or[0].key.should.equal(key)
filter.and[1].or[0].value.should.equal(value)
})
})
})