eventric
Version:
Build JavaScript applications with Behaviour-driven Domain Design. Based on DDD, BDD, CQRS and EventSourcing.
43 lines (39 loc) • 1.71 kB
JavaScript
describe('Create Aggregate Feature', function() {
return describe('given we created and initialized some example context including an aggregate', function() {
return describe('when we command the context to create an aggregate', function() {
return it('should call the create function on the aggregate with the given params', function(done) {
var Example, exampleContext;
exampleContext = eventric.context('Examplecontext');
exampleContext.defineDomainEvent('ExampleCreated', function(params) {});
Example = (function() {
function Example() {}
Example.prototype.create = function(name, email, callback) {
this.$emitDomainEvent('ExampleCreated');
return callback();
};
return Example;
})();
sandbox.spy(Example.prototype, 'create');
exampleContext.addAggregate('Example', Example);
exampleContext.addCommandHandler('CreateExample', function(params, done) {
return this.$repository('Example').create(params.name, params.email).then((function(_this) {
return function(exampleId) {
return _this.$repository('Example').save(exampleId);
};
})(this)).then(function() {
return done();
});
});
return exampleContext.initialize(function() {
return exampleContext.command('CreateExample', {
name: 'MyName',
email: 'MyEmail'
}).then(function() {
expect(Example.prototype.create).to.have.been.calledWith('MyName', 'MyEmail', sinon.match.func);
return done();
});
});
});
});
});
});