eventric-testing
Version:
Testing helpers for eventric.js
1 lines • 12.1 kB
JavaScript
require.register("eventric-testing/index",function(t,e,n){n.exports=e("./src")}),require.register("eventric-testing/src/aggregate_factory",function(t,e,n){var r,o,i,u,a;u=e("eventric"),r=u.Aggregate,i=u.Context,a=e("./stub_factory"),o=function(){function t(){}return t.prototype.fakeAggregate=function(t){var e;return e=new t,e.$emitDomainEvent=a.stub(),e},t.prototype.wiredAggregate=function(t,e){var n;return n=this.instantiateAggregateWithFakeContext(t,e),n.instance},t.prototype.instantiateAggregateWithFakeContext=function(t,e){var n;return n=this._createFakeContext(e),new r(n,u,"Aggregate",t)},t.prototype._createFakeContext=function(t){var e;return e={_eventric:u,name:"eventric-testing"},{name:e.name,getDomainEvent:function(e){return t[e]},createDomainEvent:function(){return i.prototype.createDomainEvent.apply(e,arguments)}}},t}(),n.exports=new o}),require.register("eventric-testing/src/command_query_factory",function(t,e,n){var r,o,i,u;u=e("./stub_factory"),o=e("./fake_promise"),i=e("./projection_factory"),r=function(){function t(){}return t.prototype.wiredCommandHandler=function(t){return this._wireHandler(t)},t.prototype.wiredQueryHandler=function(t){return this._wireHandler(t)},t.prototype._wireHandler=function(t){var e,n;e={$adapter:u.stub(),$aggregate:{create:u.stub(),load:u.stub()},$domainService:u.stub(),$query:u.stub(),$projectionStore:u.stub(),$emitDomainEvent:u.stub()},u.configureReturnValue(e.$aggregate.create,this.aggregateStub()),u.configureReturnValue(e.$aggregate.load,this.aggregateStub()),u.configureReturnValue(e.$projectionStore,i.mongoDbStoreStub()),t=t.bind(e);for(n in e)t[n]=e[n];return t},t.prototype.aggregateStub=function(){var t;return t=u.stub(),u.configureReturnValue(t,o.resolve()),{$save:t}},t.prototype.waitForQueryToReturnResult=function(t,e,n,r){return null==r&&(r=5e3),this.waitForResult(function(){return t.query(e,n)},r)["catch"](function(r){var o;throw(null!=r&&null!=(o=r.message)?o.indexOf("waitForResult"):void 0)>-1?new Error("waitForQueryToReturnResult timed out for query '"+e+"' on context '"+t.name+"'\nwith params "+JSON.stringify(n)):r})},t.prototype.waitForCommandToResolve=function(t,e,n,r){return null==r&&(r=5e3),this.waitForResult(function(){return t.command(e,n).then(function(t){return t||!0})["catch"](function(){return void 0})},r)["catch"](function(){throw new Error("waitForCommandToResolve timed out for command '"+e+"' on context '"+t.name+"'\nwith params "+JSON.stringify(n))})},t.prototype.waitForResult=function(t,e){return null==e&&(e=5e3),new Promise(function(n,r){var o,i;return i=new Date,(o=function(){return t().then(function(u){var a;return null!=u?void n(u):(a=new Date-i>=e,a?r(new Error("waitForResult timed out for '"+t.toString()+"'")):void setTimeout(o,15))})["catch"](r)})()})},t}(),n.exports=new r}),require.register("eventric-testing/src/domain_event_factory",function(t,e,n){var r,o,i;i=e("eventric"),r=i.DomainEvent,o=function(){function t(){}return t.prototype.createDomainEvent=function(t,e,n,o,u){var a;return a={},n.apply(a,[u]),new r({id:i.generateUid(),name:e,aggregate:{id:o,name:"eventric-testing"},context:t,payload:a})},t}(),n.exports=new o}),require.register("eventric-testing/src/fake_promise",function(t,e,n){var r,o,i=[].slice;o=function(t){return t&&"function"==typeof t.then&&"function"==typeof t["catch"]},r=function(){function t(){}return t.prototype.resolve=function(){var t;return t=1<=arguments.length?i.call(arguments,0):[],{then:function(e){var n;return null==e&&(e=function(){}),n=e.apply(this,t),o(n)?n:this},"catch":function(){return this}}},t.prototype.reject=function(){var t;return t=1<=arguments.length?i.call(arguments,0):[],{then:function(){return this},"catch":function(e){var n;return null==e&&(e=function(){}),n=e.apply(this,t),o(n),this}}},t.prototype.resolveAsync=function(){var t;return t=1<=arguments.length?i.call(arguments,0):[],{then:function(e){return null==e&&(e=function(){}),setTimeout(function(){return e.apply(this,t)},0),this},"catch":function(){return this}}},t.prototype.rejectAsync=function(){var t;return t=1<=arguments.length?i.call(arguments,0):[],{then:function(){return this},"catch":function(e){return null==e&&(e=function(){}),setTimeout(function(){return e.apply(this,t)},0),this}}},t}(),n.exports=new r}),require.register("eventric-testing/src/index",function(t,e,n){var r,o,i,u,a,s,c,g,l,m=[].slice;u=e("eventric"),g=e("./stub_factory"),r=e("./aggregate_factory"),a=e("./fake_promise"),o=e("./command_query_factory"),s=e("./projection_factory"),c=e("./remote_factory"),i=e("./domain_event_factory"),l=[],u.testing={setStubMethods:function(t,e){return g.setStubMethod(t),g.setConfigureReturnValueMethod(e)},resolve:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],a.resolve.apply(a,t)},reject:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],a.reject.apply(a,t)},resolveAsync:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],a.resolveAsync.apply(a,t)},rejectAsync:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],a.rejectAsync.apply(a,t)},fakeAggregate:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],r.fakeAggregate.apply(r,t)},wiredAggregate:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],r.wiredAggregate.apply(r,t)},wiredCommandHandler:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],o.wiredCommandHandler.apply(o,t)},wiredQueryHandler:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],o.wiredQueryHandler.apply(o,t)},wiredProjection:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],s.wiredProjection.apply(s,t)},aggregateStub:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],o.aggregateStub.apply(o,t)},wiredRemote:function(){var t,e;return t=1<=arguments.length?m.call(arguments,0):[],e=c.wiredRemote.apply(c,t),l.push(e),e},projectionStoreMongoDbStub:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],s.mongoDbStoreStub.apply(s,t)},createDomainEvent:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],i.createDomainEvent.apply(i,t)},destroy:function(){var t,e,n;for(t=0,e=l.length;e>t;t++)n=l[t],n.$destroy();return l=[]},waitForQueryToReturnResult:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],o.waitForQueryToReturnResult.apply(o,t)},waitForCommandToResolve:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],o.waitForCommandToResolve.apply(o,t)},waitForResult:function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],o.waitForResult.apply(o,t)}},n.exports=u.testing}),require.register("eventric-testing/src/projection_factory",function(t,e,n){var r,o,i,u=[].slice;o=e("./aggregate_factory"),i=e("./stub_factory"),r=function(){function t(){}return t.prototype.wiredProjection=function(){var t,e,n,r,o,i;return t=arguments[0],e=3<=arguments.length?u.call(arguments,1,r=arguments.length-1):(r=1,[]),n=arguments[r++],i=e[0],o=this._instantiateProjection(t),this._initializeProjection(o,i),this._wireProjection(o,n),o},t.prototype._instantiateProjection=function(t){var e;return e=new t,e.$store={mongodb:this.mongoDbStoreStub()},e.$adapter=i.stub(),e},t.prototype._initializeProjection=function(t,e){return t.initialize?(t.$subscribeHandlersWithAggregateId=function(e){return t.__subscribedAggregateId=e},t.initialize(e,function(){})):void 0},t.prototype._wireProjection=function(t,e){var n,r,i;return n=function(){function t(){}return t}(),r=o.instantiateAggregateWithFakeContext(n,e),i=r._handleDomainEvent,r._handleDomainEvent=function(){return i.apply({instance:t},arguments)},t.$emitDomainEvent=function(e,n,o){if(r.id=n,!t.__subscribedAggregateId||t.__subscribedAggregateId===n){if(!t["handle"+e])throw new Error("Domain Event Handler has not subscribed to domain event "+e);return r.emitDomainEvent.call(r,e,o)}},t},t.prototype.mongoDbStoreStub=function(){var t,e;e={find:i.stub(),findOne:i.stub(),update:i.stub(),upsert:i.stub(),insert:i.stub(),count:i.stub(),save:i.stub(),remove:i.stub()};for(t in e)i.configureReturnValue(e[t],null);return e},t}(),n.exports=new r}),require.register("eventric-testing/src/remote_factory",function(t,e,n){var r,o,i,u,a,s;o=e("lodash"),u=e("eventric"),i=e("./domain_event_factory"),s=e("./stub_factory"),a=e("./fake_promise"),r=function(){function t(){}return t.prototype.wiredRemote=function(t,e){var n,r,s,c,g;return g=u.remote(t),g._mostCurrentEmitOperation=a.resolve(),g._domainEvents=[],g._subscriberIds=[],g._commandStubs=[],g.addClient("inmemory",u.RemoteInMemory.client),g.set("default client","inmemory"),g.$populateWithDomainEvent=function(t,e,n){return this._domainEvents.push(this._createDomainEvent(t,e,n))},g.$emitDomainEvent=function(e,n,r){var o,i;return o=this._createDomainEvent(e,n,r),this._domainEvents.push(o),i=u.RemoteInMemory.endpoint,this._mostCurrentEmitOperation=this._mostCurrentEmitOperation.then(function(){var e,n,r;return n=i.publish(t,o),e=i.publish(t,o.name,o),o.aggregate?(r=i.publish(t,o.name,o.aggregate.id,o),Promise.all([n,e,r])):Promise.all([n,e])})},g.$waitForEmitDomainEvent=function(){return g._mostCurrentEmitOperation},g._createDomainEvent=function(n,r,o){var u;if(u=e[n],!u)throw new Error("Trying to populate wired remote with unknown domain event "+n);return i.createDomainEvent(t,n,u,r,o)},g.findDomainEventsByName=function(t){return t instanceof Array||(t=[t]),a.resolve(this._domainEvents.filter(function(e){return t.indexOf(e.name)>-1}))},g.findDomainEventsByNameAndAggregateId=function(t,e){return t instanceof Array||(t=[t]),e instanceof Array||(e=[e]),a.resolve(this._domainEvents.filter(function(n){return t.indexOf(n.name)>-1&&n.aggregate&&e.indexOf(n.aggregate.id)>-1}))},r=g.subscribeToAllDomainEvents,g.subscribeToAllDomainEvents=function(){return r.apply(this,arguments).then(function(t){return function(e){return t._subscriberIds.push(e),e}}(this))},s=g.subscribeToDomainEvent,g.subscribeToDomainEvent=function(){return s.apply(this,arguments).then(function(t){return function(e){return t._subscriberIds.push(e),e}}(this))},c=g.subscribeToDomainEventWithAggregateId,g.subscribeToDomainEventWithAggregateId=function(){return c.apply(this,arguments).then(function(t){return function(e){return t._subscriberIds.push(e),e}}(this))},g.$destroy=function(){return this._domainEvents=[],this._commandStubs=[],this._mostCurrentEmitOperation.then(function(t){return function(){var e,n,r,o,i;for(t._mostCurrentEmitOperation=a.resolve(),i=[],r=t._subscriberIds,e=0,n=r.length;n>e;e++)o=r[e],i.push(g.unsubscribeFromDomainEvent(o));return t._subscriberIds=[],Promise.all(i)}}(this))},g.$onCommand=function(t,e){var n;return n={command:t,payload:e,domainEvents:[],yieldsDomainEvent:function(t,e,n){return this.domainEvents.push({eventName:t,aggregateId:e,payload:n}),this}},this._commandStubs.push(n),n},n=g.command,g.command=function(t,e){var r,i,u,s,c,g,l,m,f;if(s=this._commandStubs.filter(function(n){return t!==n.command?!1:o.isEqual(e,n.payload)}),!s.length)return n.apply(this,arguments);for(i=function(t){return function(e){return setTimeout(function(){return t.$emitDomainEvent(e.eventName,e.aggregateId,e.payload)})}}(this),c=0,l=s.length;l>c;c++)for(u=s[c],f=u.domainEvents,g=0,m=f.length;m>g;g++)r=f[g],i(r);return a.resolve()},g},t}(),n.exports=new r}),require.register("eventric-testing/src/spec_setup",function(t,e,n){var r,o;e("es6-promise").polyfill(),r="undefined"!=typeof window?window:global,r._spec_setup||(r.sinon=e("sinon"),r.mockery=e("mockery"),r.chai=e("chai"),r.expect=chai.expect,r.sandbox=sinon.sandbox.create(),o=e("sinon-chai"),chai.use(o),r._spec_setup=!0),afterEach(function(){return sandbox.restore()})}),require.register("eventric-testing/src/stub_factory",function(t,e,n){var r;r=function(){function t(){this.stub=function(){return function(){}},this.configureReturnValue=function(){throw new Error("configureReturnValue not configured")}}return t.prototype.setStubMethod=function(t){this.stub=t},t.prototype.setConfigureReturnValueMethod=function(t){this.configureReturnValue=t},t}(),n.exports=new r});