regard
Version:
Sugar-interface to access multiple data sources.
63 lines (56 loc) • 2.27 kB
JavaScript
var _ = require('lodash'),
Chai = require('chai'),
Connector = require('../lib/connector');
var expect = Chai.expect;
var clazz = Connector,
foo;
describe('Connector', function () {
beforeEach(function () {
foo = clazz('foo');
});
it('should must have name', function () {
expect(_.partial(clazz, 'foo')).to.not.throw();
expect(clazz('foo').key).to.eql('foo');
});
it('should must have settings', function () {
expect(foo).to.have.property('context');
expect(foo.context).to.be.an('object');
});
it('should have init, checkPath, handler, onCreateEndpoint and onCreateRequest methods', function () {
_.forEach(['init', 'checkPath', 'handler', 'onCreateEndpoint', 'onCreateRequest'], function (value) {
expect(foo).to.have.property(value);
});
});
it('should init settings', function() {
foo.init({foo:'foo'}, {bar:'bar'});
expect(_.size(foo.context)).to.eql(2);
expect(foo.context.foo).to.eql('foo');
expect(foo.context.bar).to.eql('bar');
});
it('should have default checkPath method which return false', function () {
expect(foo.checkPath()).to.not.be.ok;
});
it('should have default onCreateEndpoint and onCreateRequest methods', function () {
expect(foo.onCreateEndpoint('bar')).to.eql('bar');
expect(foo.onCreateRequest('bar')).to.eql('bar');
});
it('should have handlers manager', function () {
var handlerCount = foo.handlers.data.length,
handler;
expect(foo.handlers).to.be.an('object');
expect(foo.handler).to.throw();
expect(foo.handlers.data.length).to.eql(handlerCount);
handler = foo.handler(_.identity);
expect(foo.handlers.data.length).to.eql(handlerCount+1);
handler = foo.handler('foo', _.identity);
expect(foo.handlers.data.length).to.eql(handlerCount+2);
handler = foo.handler('bar', {process:_.identity});
expect(foo.handlers.data.length).to.eql(handlerCount+3);
handler = foo.handler('bax', _.identity, {process:_.identity});
expect(foo.handlers.data.length).to.eql(handlerCount+4);
});
it('should generate connector name based on filename', function () {
expect(clazz.generateKey('/foo/bar.js')).to.eql('bar');
expect(clazz.generateKey('/foo/bar')).to.eql('bar');
});
});