eventric
Version:
Build JavaScript applications with Behaviour-driven Domain Design. Based on DDD, BDD, CQRS and EventSourcing.
63 lines (51 loc) • 2.26 kB
text/coffeescript
describe 'Projection Feature', ->
describe 'given we created and initialized some example context including a Projection', ->
exampleContext = null
beforeEach ->
exampleContext = eventric.context 'exampleContext'
exampleContext.defineDomainEvents
ExampleCreated: ->
SomethingHappened: (params) ->
= params.whateverFoo
exampleContext.addProjection 'ExampleProjection', ->
stores: ['inmemory']
handleSomethingHappened: (domainEvent, done) ->
.inmemory.totallyDenormalized = domainEvent.payload.specific
done()
exampleContext.addAggregate 'Example', ->
create: (callback) ->
'ExampleCreated'
callback()
handleExampleCreated: (domainEvent) ->
= 'bar'
doSomething: ->
if is 'bar'
'SomethingHappened', whateverFoo: 'foo'
handleSomethingHappened: (domainEvent) ->
= domainEvent.payload.whateverFoo
exampleContext.addCommandHandlers
CreateExample: (params, callback) ->
exampleId = null
.create()
.then (exampleId) =>
.save exampleId
.then (exampleId) ->
callback null, exampleId
doSomethingWithExample: (params, callback) ->
.findById params.id
.then (example) =>
example.doSomething()
.save params.id
.then ->
callback()
exampleContext.initialize()
.then ->
exampleContext.enableWaitingMode()
describe 'when DomainEvents got emitted which the Projection subscribed to', ->
it 'then the Projection should call the projectionStore with the denormalized state', ->
exampleContext.command 'CreateExample'
.then (exampleId) ->
exampleContext.command 'doSomethingWithExample', id: exampleId
.then ->
exampleContext.getProjectionStore 'inmemory', 'ExampleProjection', (err, projectionStore) ->
expect(projectionStore).to.deep.equal totallyDenormalized: 'foo'