UNPKG

regard

Version:

Sugar-interface to access multiple data sources.

47 lines (40 loc) 1.41 kB
var _ = require('lodash'), Chai = require('chai'), Connector = require('../lib/connector'), FsConnector = require('../lib/connectors/fs'), Endpoint = require('../lib/endpoint'), Request = require('../lib/request'); var expect = Chai.expect; var clazz = Request, foo, bar; describe('Request', function () { beforeEach(function () { var connector = FsConnector(); var endpoint = Endpoint('foo'); endpoint.init('foo', {foo:'foo',$connector:connector}); bar = Endpoint('bar'); bar.init('bar', {bar:'bar',$connector:connector}); bar.parent = endpoint; foo = clazz('hash'); }); it('should return Endpoint instance', function () { foo = clazz(); expect(foo).is.be.instanceof(Request); foo = new clazz(); expect(foo).is.be.instanceof(Request); }); it('should must have key, args, context, endpoint, handler and path properties', function () { _.each(['key', 'args', 'context', 'endpoint', 'handler', 'path'], function (value) { expect(foo).to.have.property(value); }); }); it('should init request', function () { foo.init(bar, 'default', {x:'y'}); expect(foo.key).to.eql('hash'); expect(foo.args).to.eql({x:'y'}); expect(foo.handler).to.eql('default'); expect(foo.path).to.eql('foo/bar'); expect(foo.context.foo).to.eql('foo'); expect(foo.context.bar).to.eql('bar'); }); });