node-cqrs-domain icon indicating copy to clipboard operation
node-cqrs-domain copied to clipboard

manually build aggregate state for unit testing

Open developmentalmadness opened this issue 8 years ago • 5 comments

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?

developmentalmadness avatar Aug 22 '16 17:08 developmentalmadness

In theory yes

adrai avatar Aug 22 '16 21:08 adrai

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

adrai avatar Aug 22 '16 21:08 adrai

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

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

adrai avatar Aug 22 '16 21:08 adrai

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?

developmentalmadness avatar Aug 22 '16 22:08 developmentalmadness

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

adrai avatar Aug 23 '16 04:08 adrai