1 | describe 'eventric', ->
|
2 |
|
3 | domainEventSpecHelper = require 'eventric/domain_event/domain_event.spec_helper'
|
4 |
|
5 | Context = null
|
6 |
|
7 | beforeEach ->
|
8 | Context = require './context'
|
9 |
|
10 |
|
11 | describe '#context', ->
|
12 |
|
13 | it 'should generate a new eventric context', ->
|
14 | context = eventric.context 'context'
|
15 | expect(context).to.be.an.instanceOf Context
|
16 |
|
17 |
|
18 | it 'should subscribe to all domain events of the context', ->
|
19 | sandbox.spy Context::, 'subscribeToAllDomainEvents'
|
20 | context = eventric.context 'context'
|
21 | expect(context.subscribeToAllDomainEvents).to.have.been.called
|
22 |
|
23 |
|
24 | it 'should delegate any event from the context to all remote endpoints', (done) ->
|
25 | contextName = 'context'
|
26 | domainEvent = domainEventSpecHelper.createDomainEvent 'SomeDomainEvent'
|
27 | domainEvent.context = contextName
|
28 | sandbox.stub(Context::, 'subscribeToAllDomainEvents').yields domainEvent
|
29 |
|
30 | inmemoryRemoteEndpoint = require('eventric-remote-inmemory').endpoint
|
31 | sandbox.stub inmemoryRemoteEndpoint, 'publish'
|
32 |
|
33 | eventric.context contextName
|
34 |
|
35 | setTimeout ->
|
36 | expect(inmemoryRemoteEndpoint.publish).to.have.been.calledWith contextName, 'SomeDomainEvent', domainEvent
|
37 | expect(inmemoryRemoteEndpoint.publish).to.have.been.calledWith contextName, 'SomeDomainEvent', sinon.match.string,
|
38 | domainEvent
|
39 | done()
|
40 |
|
41 |
|
42 | describe '#getRegisteredContextNames', ->
|
43 |
|
44 | it 'should return all names of all registered contexts', ->
|
45 | eventric.context 'context1'
|
46 | eventric.context 'context2'
|
47 | contextNames = eventric.getRegisteredContextNames()
|
48 | expect(contextNames).to.deep.equal ['context1', 'context2']
|
49 |
|
50 |
|
51 | describe '#generateUuid', ->
|
52 |
|
53 | it 'should ask the uuid generator to generate a uuid', ->
|
54 | uuidGenerator = require './uuid_generator'
|
55 | sandbox.spy uuidGenerator, 'generateUuid'
|
56 | eventric.generateUuid()
|
57 | expect(uuidGenerator.generateUuid).to.have.been.called
|