eventric
Version:
Build JavaScript applications with Behaviour-driven Domain Design. Based on DDD, BDD, CQRS and EventSourcing.
35 lines (27 loc) • 1.34 kB
text/coffeescript
describe 'DomainService Feature', ->
describe 'given we created and initialized some example context including a domain service', ->
exampleContext = null
specialStub = null
beforeEach ->
exampleContext = eventric.context 'exampleContext'
exampleContext.defineDomainEvent 'SomethingHappened', ->
exampleContext.addCommandHandler 'DoSomething', (params, callback) ->
@$domainService 'DoSomethingSpecial', params, callback
specialStub = sandbox.stub()
exampleContext.addDomainService 'DoSomethingSpecial', (params, callback) ->
specialStub params.special
@$emitDomainEvent 'SomethingHappened'
callback null, true
describe 'when we call the command', ->
it 'then the domain service should be executed correctly', (done) ->
exampleContext.initialize =>
exampleContext.command 'DoSomething', special: 'awesome'
.then =>
expect(specialStub).to.have.been.calledWith 'awesome'
done()
it 'then should have emitted the correct domain event', (done) ->
exampleContext.subscribeToDomainEvent 'SomethingHappened', (domainEvent) ->
expect(domainEvent.name).to.be.ok
done()
exampleContext.initialize =>
exampleContext.command 'DoSomething', special: 'awesome'