Start filter.Filter unit tests

master
garrettmills 4 years ago
parent e430a92431
commit 485ba055af
No known key found for this signature in database
GPG Key ID: 6ACD58D6ADACFC6E

@ -11,14 +11,14 @@ const { ObjectId } = require('mongodb')
* @class
*/
class Filter {
constructor(model) {
/**
* The root query object.
* @type {object}
* @private
*/
this._root = {$and: []}
/**
* The root query object.
* @type {object}
* @private
*/
_root = {$and: []}
constructor(model) {
/**
* The model in question.
* @type: {module:flitter-orm/src/model/Model}

@ -1,5 +1,6 @@
- schema.Schema
- model.Model
- filter.Filter/filter.Focus
Integration
- relations

@ -0,0 +1,82 @@
const { expect } = require('chai')
const sinon = require('sinon')
const Filter = require('../../src/filter/Filter')
const Focus = require('../../src/filter/Focus')
const FilterProxy = require('../../src/proxy/model/FilterProxy')
describe('the accumulating filter class', function() {
let filter
let fake_model
beforeEach(function() {
fake_model = {}
filter = new Filter(fake_model)
})
it('should have a base root property', function() {
expect(filter._root).to.be.eql({$and: []})
})
it('should set the model on construction', function() {
expect(filter._model).to.be.equal(fake_model)
})
describe('the clone method', function() {
it('should be a function', function() {
expect(filter.clone).to.be.a('function')
})
it('should return a new filter', function() {
expect(filter.clone()).to.be.an.instanceof(Filter)
expect(filter.clone()).to.not.be.equal(filter)
})
it('should focus on the same model', function() {
expect(filter.clone()._model).to.be.equal(fake_model)
})
it('should have a different root object', function() {
expect(filter.clone()._root).to.not.be.equal(filter._root)
expect(filter.clone()._root).to.be.eql(filter._root)
})
})
describe('the field method', function() {
it('should be a function', function() {
expect(filter.field).to.be.a('function')
})
it('should expect one argument', function() {
expect(filter.field.length).to.be.equal(1)
})
it('should return a new Focus object', function() {
const focus = filter.field('test_field')
expect(focus).to.be.an.instanceof(Focus)
expect(focus._parent).to.be.equal(filter)
expect(focus._field).to.be.equal('test_field')
})
})
describe('the end method', function() {
it('should be a function', function() {
expect(filter.end).to.be.a('function')
})
it('should return a filter proxy', function() {
const fp = filter.end()
expect(fp).to.be.an.instanceof(FilterProxy)
})
})
// TODO describe the equal method
// TODO describe the less_than method
// TODO describe the greater_than method
// TODO describe the less_than_equal method
// TODO describe the greater_than_equal method
// TODO describe the in method
// TODO describe the write method
// TODO describe the __exec_resolve method
// TODO describe the absorb method
// TODO describe the _unfocus method
})

@ -54,7 +54,10 @@ describe('the base model class', function() {
expect(Model.scopes.length).to.be.equal(0)
})
// TODO describe the schema getter
it('should have a __static schema getter', function() {
expect(Model.__schema).to.exist
expect(Model.__schema).to.be.an.instanceof(Schema)
})
it('should have a static collection getter', function() {
expect(Model.collection).to.exist
@ -144,7 +147,6 @@ describe('the base model class', function() {
})
})
// TODO describe the find method
describe('the static find method', function() {
function check_range(input, min = 1, max = 100) {
const should_have = (max - min) + 1
@ -257,7 +259,6 @@ describe('the base model class', function() {
})
})
// TODO describe the findOne method
describe('the static findOne method', function() {
beforeEach(async function() {
for ( let i = 1; i <= 100; i++ ) {
@ -304,7 +305,6 @@ describe('the base model class', function() {
// TODO it should respect scopes applied to the model
})
// TODO describe the deleteOne method
describe('the static deleteOne method', function() {
beforeEach(async function() {
for ( let i = 1; i <= 100; i++ ) {
@ -360,7 +360,6 @@ describe('the base model class', function() {
// TODO it should respect scopes applied to the model
})
// TODO describe the deleteMany method
describe('the static deleteMany method', function() {
beforeEach(async function() {
for ( let i = 1; i <= 100; i++ ) {
@ -443,7 +442,6 @@ describe('the base model class', function() {
})
})
// TODO describe the count method
describe('the static count method', function() {
beforeEach(async function() {
for ( let i = 1; i <= 100; i++ ) {

Loading…
Cancel
Save