UNPKG

regard

Version:

Sugar-interface to access multiple data sources.

61 lines (55 loc) 2.02 kB
var _ = require('lodash'), Chai = require('chai'), AbstractManager = require('../../lib/managers/abstract'); var clazz = AbstractManager, expect = Chai.expect, foo, bar; describe('AbstractManager', function () { beforeEach(function () { foo = clazz(); }); it('should return AbstractManager instance', function () { foo = clazz(); expect(foo).is.be.instanceof(AbstractManager); foo = new clazz(); expect(foo).is.be.instanceof(AbstractManager); }); it('should have data and index properties', function () { expect(foo).to.have.property('data'); expect(foo).to.have.property('index'); }); it('should have add, get and has methods', function () { expect(foo.add).to.be.a('function'); expect(foo.get).to.be.a('function'); expect(foo.has).to.be.a('function'); }); it('should add item in data and index the key', function () { expect(_.find(foo.data, 'key', 'bar')).to.not.be.ok; expect(_.includes(foo.index, 'bar')).to.not.be.ok; foo.add({key:'bar'}); expect(_.find(foo.data, 'key', 'bar')).to.be.ok; expect(_.includes(foo.index, 'bar')).to.be.ok; }); it('should throw exception if new data do not have key', function () { expect(_.bind(foo.add, foo, {})).to.throw(); expect(_.bind(foo.add, foo, {key:''})).to.throw(); expect(_.bind(foo.add, foo, {key:[]})).to.throw(); }); it('should throw exception if data already exists with the new data key', function () { expect(foo.data.length).to.eql(0); foo.add({key:'bar'}); expect(foo.data.length).to.eql(1); foo.add({key:'bar'}); expect(foo.data.length).to.eql(1); }); it('should return data bound with the given key', function () { expect(foo.get('bar')).to.not.be.ok; foo.add({key:'bar'}); expect(foo.get('bar')).to.be.ok; }); it('should return true if data exists with the given key', function () { expect(foo.has('bar')).to.not.be.ok; foo.add({key:'bar'}); expect(foo.has('bar')).to.be.ok; }); });