Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods committed Aug 16, 2024
1 parent 5518434 commit 70b1025
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 21 deletions.
33 changes: 19 additions & 14 deletions codegen/projections/white_label/spec/event_stream_stubs_spec.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,23 @@
end

let(:nested_event) do
WhiteLabel::Types::NestedEvent.new(
nested: complex_data,
header_a: event_header,
message: event_message
WhiteLabel::Params::NestedEvent.build(
{
nested: complex_data,
header_a: event_header,
message: event_message
},
context: 'stub'
)
end

let(:explicit_payload_event) do
WhiteLabel::Types::ExplicitPayloadEvent.new(
header_a: event_header,
payload: complex_data
WhiteLabel::Params::ExplicitPayloadEvent.build(
{
header_a: event_header,
payload: complex_data
},
context: 'stub'
)
end

Expand Down
58 changes: 58 additions & 0 deletions hearth/lib/hearth/client_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,64 @@ module ClientStubs
# resp = client.operation(param1: 'value2')
# resp.data.content_length #=> 150
#
# ## Stubbing Event Stream operations
#
# Operations with event stream responses may also be stubbed using
# {#stub_responses} to stub both initial responses and events.
# By default, the SDK will generate a fake initial response and event.
#
# client = Service::Client.new(stub_responses: true)
# handler = Service::EventStreams::EventStreamOperationHandler.new
# handler.on_initial_response { |event| # default initial response }
# handler.on_event_1 { |event| # default event }
# client.event_stream_operation({}, event_stream_handler: handler)
#
# You may specify events and initial responses together using the :events
# and :initial_responses keys.
#
# client = Service::Client.new(stub_responses: true)
# client.stub_responses(:event_stream_operation, {
# events: [Service::Types:::MyEvent.new(message: 'message')],
# initial_response: { params1: 'value1' }
# })
# handler = Service::EventStreams::EventStreamOperationHandler.new
# handler.on_initial_response { |event| # stubbed initial response }
# handler.on_my_event { |event| # stubbed MyEvent }
# client.event_stream_operation({}, event_stream_handler: handler)
#
# :events may be either an event Type or a {EventStream::Message}.
# :initial_response may be the operation's output Type, a hash with the
# outputs parameters, or a protocol Response. If the :initial_response is
# a Response, then the body should be unset or an {EventStream::Message}.
# Stubbed event stream events and initial responses will trigger synchronous
# calls to registered event stream handlers.
#
# ## Stubbing Event Stream Errors
#
# You may stub event stream errors in a number of different ways, depending
# on the type of error. For Exceptions raised during the request and
# when connecting, you may pass the exception and the operation call will
# raise the error:
# client.stub_responses(
# :event_stream_operation, Hearth::NetworkingError.new)
# client.event_stream_operation
# #=> raises Hearth::NetworkingError
#
# To stub modeled/service errors, you may pass an instance of the error and
# the registered error handlers will be called.
#
# client.stub_responses(
# :event_stream_operation, Service::ClientError.new)
# handler = Service::EventStreams::EventStreamOperationHandler.new
# handler.on_error { |e| # ClientError }
# client.event_stream_operation({}, event_stream_handler: handler)
#
# ## Dynamic stubbing for event streams
#
# Similar to regular operations, event streaming operations also support
# dynamic stubbing based on the input by passing a `Proc` object which
# returns any of the supported stubs types.
#
# @param [Symbol] operation_name
#
# @param [Mixed] stubs One or more responses to return from the named
Expand Down

0 comments on commit 70b1025

Please sign in to comment.