UNPKG

eventric

Version:

Build JavaScript applications with Behaviour-driven Domain Design. Based on DDD, BDD, CQRS and EventSourcing.

48 lines (47 loc) 1.89 kB
describe('DomainService Feature', function() { return describe('given we created and initialized some example context including a domain service', function() { var exampleContext, specialStub; exampleContext = null; specialStub = null; beforeEach(function() { exampleContext = eventric.context('exampleContext'); exampleContext.defineDomainEvent('SomethingHappened', function() {}); exampleContext.addCommandHandler('DoSomething', function(params, callback) { return this.$domainService('DoSomethingSpecial', params, callback); }); specialStub = sandbox.stub(); return exampleContext.addDomainService('DoSomethingSpecial', function(params, callback) { specialStub(params.special); this.$emitDomainEvent('SomethingHappened'); return callback(null, true); }); }); return describe('when we call the command', function() { it('then the domain service should be executed correctly', function(done) { return exampleContext.initialize((function(_this) { return function() { return exampleContext.command('DoSomething', { special: 'awesome' }).then(function() { expect(specialStub).to.have.been.calledWith('awesome'); return done(); }); }; })(this)); }); return it('then should have emitted the correct domain event', function(done) { exampleContext.subscribeToDomainEvent('SomethingHappened', function(domainEvent) { expect(domainEvent.name).to.be.ok; return done(); }); return exampleContext.initialize((function(_this) { return function() { return exampleContext.command('DoSomething', { special: 'awesome' }); }; })(this)); }); }); }); });