|
| 1 | +// Copyright (c) Dolittle. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +import { describeThis } from '@dolittle/typescript.testing'; |
| 5 | + |
| 6 | +import { EventSourceId } from '@dolittle/sdk.events'; |
| 7 | + |
| 8 | +import { AnAggregateRoot } from './given/an_aggregate_root'; |
| 9 | +import { event_types, EventWithOnMethod, EventWithoutOnMethod } from './given/events'; |
| 10 | + |
| 11 | +describeThis(__filename, () => { |
| 12 | + let event_source: EventSourceId; |
| 13 | + let aggregate_root: AnAggregateRoot; |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + event_source = EventSourceId.from('f77f4484-e683-4971-9b90-4cbfafbd21f2'); |
| 17 | + aggregate_root = new AnAggregateRoot(event_source); |
| 18 | + aggregate_root.eventTypes = event_types(); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('that does not have an on-method', () => { |
| 22 | + let event: EventWithoutOnMethod; |
| 23 | + |
| 24 | + beforeEach(() => { |
| 25 | + event = new EventWithoutOnMethod('property'); |
| 26 | + aggregate_root.applyWithoutOnMethod(event); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should have applied one event', () => aggregate_root.appliedEvents.should.have.length(1)); |
| 30 | + it('should have applied the correct event', () => aggregate_root.appliedEvents[0].event.should.equal(event)); |
| 31 | + it('should not apply the event as public', () => aggregate_root.appliedEvents[0].isPublic.should.be.false); |
| 32 | + it('should not have called an on-method', () => aggregate_root.onMethodEventsCalled.should.have.length(0)); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('that has an on-method', () => { |
| 36 | + let event: EventWithOnMethod; |
| 37 | + |
| 38 | + beforeEach(() => { |
| 39 | + event = new EventWithOnMethod(42); |
| 40 | + aggregate_root.applyWithOnMethod(event); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should have applied one event', () => aggregate_root.appliedEvents.should.have.length(1)); |
| 44 | + it('should have applied the correct event', () => aggregate_root.appliedEvents[0].event.should.equal(event)); |
| 45 | + it('should not apply the event as public', () => aggregate_root.appliedEvents[0].isPublic.should.be.false); |
| 46 | + it('should not have called an on-method', () => aggregate_root.onMethodEventsCalled.should.have.length(1)); |
| 47 | + it('should call the on-method with the correct event', () => aggregate_root.onMethodEventsCalled[0].should.equal(event)); |
| 48 | + }); |
| 49 | +}); |
0 commit comments