From afc85e6a098d0f2ad8e4e2af86e9d130792b3780 Mon Sep 17 00:00:00 2001 From: Erik Rozendaal Date: Wed, 8 Jan 2025 17:36:29 +0100 Subject: [PATCH] Reload aggregates from existing and new events in fake event store --- lib/sequent/test/command_handler_helpers.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/sequent/test/command_handler_helpers.rb b/lib/sequent/test/command_handler_helpers.rb index ff190e52..e01b0cdd 100644 --- a/lib/sequent/test/command_handler_helpers.rb +++ b/lib/sequent/test/command_handler_helpers.rb @@ -164,16 +164,18 @@ def then_no_events def to_event_streams(uncommitted_events) # Specs use a simple list of given events. # We need a mapping from StreamRecord to the associated events for the event store. - uncommitted_events.group_by(&:aggregate_id).values.map do |events| - aggregate_type = aggregate_type_for_event(events[0]) + uncommitted_events.group_by(&:aggregate_id).map do |aggregate_id, new_events| + _, existing_events = Sequent.configuration.event_store.load_events(aggregate_id) || [nil, []] + all_events = existing_events + new_events + aggregate_type = aggregate_type_for_event(all_events[0]) unless aggregate_type fail <<~EOS - Cannot find aggregate type associated with creation event #{events[0]}, did you include an event handler in your aggregate for this event? + Cannot find aggregate type associated with creation event #{all_events[0]}, did you include an event handler in your aggregate for this event? EOS end - aggregate = aggregate_type.load_from_history(nil, events) - [aggregate.event_stream, events] + aggregate = aggregate_type.load_from_history(nil, all_events) + [aggregate.event_stream, new_events] end end