thenativeweb / node-cqrs-domain

Node-cqrs-domain is a node.js module based on nodeEventStore that. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
http://cqrs.js.org/pages/domain.html
MIT License
269 stars 57 forks source link

manually build aggregate state for unit testing #79

Open developmentalmadness opened 8 years ago

developmentalmadness commented 8 years ago

Is there a way to manually set the state of an aggregate instance? Currently I am defining and handling all the commands it takes to put an aggregate instance in a specific state. Instead is there a way to just assume it correctly arrived at that state (like passing in a snapshot) and then handle the event?

adrai commented 8 years ago

In theory yes

adrai commented 8 years ago

But it's a hack and I would not recommend it

adrai commented 8 years ago

You could try to set modelInitValues before handling a command...

something like require('./myaggr').modelInitValues = {};

developmentalmadness commented 8 years ago

maybe I'm thinking of this in the wrong way. How would you recommend setting up aggregates for testing individual commands? Is there a reference sample somewhere I could look at? Or is the accepted method just handling an entire list of events for a given scenario?

adrai commented 8 years ago

I do it always, like the integrationTests: send a couple of commands...