eventric
Version:
Build JavaScript applications with Behaviour-driven Domain Design. Based on DDD, BDD, CQRS and EventSourcing.
68 lines (53 loc) • 2.21 kB
text/coffeescript
describe 'ProcessManager', ->
describe 'given we created a context and added a ProcessManager', ->
initializeProcessManagerStub = null
handleDomainEventProcessManagerStub = null
exampleContext = null
beforeEach ->
initializeProcessManagerStub = sandbox.stub()
handleDomainEventProcessManagerStub = sandbox.stub()
eventric.addProcessManager 'ExampleProcess',
initializeWhen:
Example: [
'ExampleCreated'
]
class: ->
initialize: (domainEvent) ->
initializeProcessManagerStub()
exampleContext.command 'ChangeExample',
id: domainEvent.aggregate.id
fromExample_handleExampleChanged: ->
handleDomainEventProcessManagerStub()
exampleContext = eventric.context 'Example'
exampleContext.defineDomainEvents
ExampleCreated: ->
ExampleChanged: ->
class ExampleAggregateRoot
create: (callback) ->
'ExampleCreated'
callback()
doSomething: ->
'ExampleChanged'
exampleContext.addAggregate 'Example', ExampleAggregateRoot
exampleContext.addCommandHandler 'CreateExample', (params, callback) ->
.create()
.then (exampleId) =>
.save exampleId
.then =>
callback()
exampleContext.addCommandHandler 'ChangeExample', (params, callback) ->
.findById params.id
.then (example) =>
example.doSomething()
.save params.id
.then =>
callback()
exampleContext.initialize()
describe 'when a DomainEvent gets emitted the ProcessManager defined as initializeWhen', ->
it 'then it should execute and end the process', (done) ->
exampleContext.subscribeToDomainEvent 'ExampleChanged', (domainEvent) ->
expect(initializeProcessManagerStub).to.have.been.called
expect(handleDomainEventProcessManagerStub).to.have.been.called
done()
exampleContext.command 'CreateExample'