node-fit-model
Version:
Checks whether an object is fits into a model.
67 lines (38 loc) • 1.42 kB
JavaScript
/**
* Test to make sure canBeEmpty parameter is valid
*
**/
var expect = require('chai').expect,
options = {
modelDir: __dirname + '/data',
postFix: 'Model.js'
},
fitModel = require('./../index'),
modelling = new fitModel(options),
data = require('./TestObject');
describe('canBeEmpty Parameter', function () {
// Array
it('should not throw if the array exists and the parameter canBeEmpty', function(){
expect(modelling.fitModel('User', data)).to.equal(true);
});
it('should throw if the canBeEmpty is not true and the array is empty', function(){
var copy = JSON.parse(JSON.stringify(data));
copy.activities = [];
expect(function() {
modelling.fitModel('User', copy)
}).to.throw('Value of activities must be array(Activity)');
});
// Objects
it('should not throw if the object exists and the parameter canBeEmpty is true', function(){
var copy = JSON.parse(JSON.stringify(data));
copy.lastActivity = {};
expect(modelling.fitModel('User', copy)).to.equal(true);
});
it('should throw if the canBeEmpty is not true and the object is empty', function(){
var copy = JSON.parse(JSON.stringify(data));
copy.review = {};
expect(function() {
modelling.fitModel('User', copy)
}).to.throw();
});
});