eventric-testing
Version:
Testing helpers for eventric.js
1 lines • 7.73 kB
JavaScript
require.register("eventric-testing/index",function(t,n,e){e.exports=n("./src")}),require.register("eventric-testing/src/aggregate_factory",function(t,n,e){var r,o;o=n("eventric"),r=function(){function t(){}return t.prototype.createAggregateInstance=function(t,n){return t=o.context(Math.random()),t.defineDomainEvents(domainEvents),t.addAggregate("test",AggregateClass),t.addCommandHandlers({CreateAggregate:function(){}}),aggregate.instance},t}(),e.exports=new r}),require.register("eventric-testing/src/eventual_consistency_utilities",function(t,n,e){var r;r=function(){function t(){}return t.prototype.waitForQueryToReturnResult=function(t,n,e,r){return null==r&&(r=5e3),this.waitForResult(function(){return t.query(n,e)},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 '"+n+"' on context '"+t.name+"'\nwith params "+JSON.stringify(e)):r})},t.prototype.waitForCommandToResolve=function(t,n,e,r){return null==r&&(r=5e3),this.waitForResult(function(){return t.command(n,e).then(function(t){return t||!0})["catch"](function(){return void 0})},r)["catch"](function(){throw new Error("waitForCommandToResolve timed out for command '"+n+"' on context '"+t.name+"'\nwith params "+JSON.stringify(e))})},t.prototype.waitForResult=function(t,n){return null==n&&(n=5e3),new Promise(function(e,r){var o,i;return i=new Date,(o=function(){return t().then(function(u){var a;return null!=u?void e(u):(a=new Date-i>=n,a?r(new Error("waitForResult timed out for '"+t.toString()+"'")):void setTimeout(o,15))})["catch"](r)})()})},t}(),e.exports=new r}),require.register("eventric-testing/src/fake_promise",function(t,n,e){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(n){var e;return null==n&&(n=function(){}),e=n.apply(this,t),o(e)?e: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(n){var e;return null==n&&(n=function(){}),e=n.apply(this,t),o(e),this}}},t.prototype.resolveAsync=function(){var t;return t=1<=arguments.length?i.call(arguments,0):[],{then:function(n){return null==n&&(n=function(){}),setTimeout(function(){return n.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(n){return null==n&&(n=function(){}),setTimeout(function(){return n.apply(this,t)},0),this}}},t}(),e.exports=new r}),require.register("eventric-testing/src/index",function(t,n,e){var r,o,i,u,a,s,c=[].slice;o=n("./aggregate_factory"),u=n("./fake_promise"),i=n("./eventual_consistency_utilities"),a=n("./remote_factory"),s=[],r=function(){function t(){}return t.prototype.resolve=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],u.resolve.apply(u,t)},t.prototype.reject=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],u.reject.apply(u,t)},t.prototype.resolveAsync=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],u.resolveAsync.apply(u,t)},t.prototype.rejectAsync=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],u.rejectAsync.apply(u,t)},t.prototype.wiredAggregate=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],o.wiredAggregate.apply(o,t)},t.prototype.wiredRemote=function(){var t,n;return t=1<=arguments.length?c.call(arguments,0):[],n=a.wiredRemote.apply(a,t),s.push(n),n},t.prototype.destroy=function(){var t,n,e;for(t=0,n=s.length;n>t;t++)e=s[t],e.$destroy();return s=[]},t.prototype.waitForQueryToReturnResult=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],i.waitForQueryToReturnResult.apply(i,t)},t.prototype.waitForCommandToResolve=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],i.waitForCommandToResolve.apply(i,t)},t.prototype.waitForResult=function(){var t;return t=1<=arguments.length?c.call(arguments,0):[],i.waitForResult.apply(i,t)},t}(),e.exports=new r}),require.register("eventric-testing/src/remote_factory",function(t,n,e){var r,o,i,u,a;o=n("lodash"),i=n("eventric"),u=n("./fake_promise"),a=n("eventric-remote-inmemory"),r=function(){function t(){}return t.prototype.wiredRemote=function(t,n){var e,r,s,c,l;return l=i.remote(t),l._mostCurrentEmitOperation=u.resolve(),l._domainEvents=[],l._subscriberIds=[],l._commandStubs=[],l._context=i.context(t),l.setClient(a.client),l.$populateWithDomainEvent=function(t,n,e){return this._domainEvents.push(this._createDomainEvent(t,n,e))},l.$emitDomainEvent=function(n,e,r){var o,i;return o=this._createDomainEvent(n,e,r),this._domainEvents.push(o),i=a.endpoint,this._mostCurrentEmitOperation=this._mostCurrentEmitOperation.then(function(){var n,e,r;return e=i.publish(t,o),n=i.publish(t,o.name,o),o.aggregate?(r=i.publish(t,o.name,o.aggregate.id,o),Promise.all([e,n,r])):Promise.all([e,n])})},l.$waitForEmitDomainEvent=function(){return l._mostCurrentEmitOperation},l._createDomainEvent=function(t,e,r){var o;if(o=n[t],!o)throw new Error("Trying to populate wired remote with unknown domain event "+t);return l._context.createDomainEvent(t,o,r,{id:e})},l.findDomainEventsByName=function(t){return t instanceof Array||(t=[t]),u.resolve(this._domainEvents.filter(function(n){return t.indexOf(n.name)>-1}))},l.findDomainEventsByNameAndAggregateId=function(t,n){return t instanceof Array||(t=[t]),n instanceof Array||(n=[n]),u.resolve(this._domainEvents.filter(function(e){return t.indexOf(e.name)>-1&&e.aggregate&&n.indexOf(e.aggregate.id)>-1}))},r=l.subscribeToAllDomainEvents,l.subscribeToAllDomainEvents=function(){return r.apply(this,arguments).then(function(t){return function(n){return t._subscriberIds.push(n),n}}(this))},s=l.subscribeToDomainEvent,l.subscribeToDomainEvent=function(){return s.apply(this,arguments).then(function(t){return function(n){return t._subscriberIds.push(n),n}}(this))},c=l.subscribeToDomainEventWithAggregateId,l.subscribeToDomainEventWithAggregateId=function(){return c.apply(this,arguments).then(function(t){return function(n){return t._subscriberIds.push(n),n}}(this))},l.$destroy=function(){return this._domainEvents=[],this._commandStubs=[],this._mostCurrentEmitOperation.then(function(t){return function(){var n,e,r,o,i;for(t._mostCurrentEmitOperation=u.resolve(),i=[],r=t._subscriberIds,n=0,e=r.length;e>n;n++)o=r[n],i.push(l.unsubscribeFromDomainEvent(o));return t._subscriberIds=[],Promise.all(i)}}(this))},l.$onCommand=function(t,n){var e;return e={command:t,payload:n,domainEvents:[],yieldsDomainEvent:function(t,n,e){return this.domainEvents.push({eventName:t,aggregateId:n,payload:e}),this}},this._commandStubs.push(e),e},e=l.command,l.command=function(t,n){var r,i,a,s,c,l,m,f,p;if(s=this._commandStubs.filter(function(e){return t!==e.command?!1:o.isEqual(n,e.payload)}),!s.length)return e.apply(this,arguments);for(i=function(t){return function(n){return setTimeout(function(){return t.$emitDomainEvent(n.eventName,n.aggregateId,n.payload)})}}(this),c=0,m=s.length;m>c;c++)for(a=s[c],p=a.domainEvents,l=0,f=p.length;f>l;l++)r=p[l],i(r);return u.resolve()},l},t}(),e.exports=new r}),require.register("eventric-testing/src/spec_setup",function(t,n,e){var r,o;n("es6-promise").polyfill(),r="undefined"!=typeof window?window:global,r._spec_setup||(r.sinon=n("sinon"),r.chai=n("chai"),r.expect=chai.expect,r.sandbox=sinon.sandbox.create(),o=n("sinon-chai"),chai.use(o),r._spec_setup=!0),afterEach(function(){return sandbox.restore()})});