Skip to content

Commit

Permalink
Add stored_events helper to retrieve events since last command
Browse files Browse the repository at this point in the history
Mark the position in the event store when executing a command. The
`stored_event` and `then_events` helpers retrieve and compare the
events stored since the last command execution.
  • Loading branch information
erikrozendaal committed Jan 9, 2025
1 parent afc85e6 commit c0624e1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/sequent/test/command_handler_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,14 @@ def given_events(*events)
Sequent::Core::BaseCommand.new,
to_event_streams(events.flatten(1)),
)
@helpers_given_events_position_mark = Sequent.configuration.event_store.position_mark
end

def when_command(command)
@helpers_events_position_mark = Sequent.configuration.event_store.position_mark
Sequent.configuration.command_service.execute_commands command
end

def then_events(*expected_events)
stored_events, @helpers_given_events_position_mark =
Sequent.configuration.event_store.load_events_since_marked_position(@helpers_given_events_position_mark)

expected_classes = expected_events.flatten(1).map { |event| event.instance_of?(Class) ? event : event.class }
expect(stored_events.map(&:class)).to eq(expected_classes)

Expand All @@ -159,6 +156,10 @@ def then_no_events
then_events
end

def stored_events
Sequent.configuration.event_store.load_events_since_marked_position(@helpers_events_position_mark)[0]
end

private

def to_event_streams(uncommitted_events)
Expand Down

0 comments on commit c0624e1

Please sign in to comment.