Module: Tpt::Rails::EventBridgeTestHelper

Defined in:
app/helpers/tpt/rails/event_bridge_test_helper.rb

Class Method Summary collapse

Class Method Details

.publisher(batch_size: 10, stub_responses: {}) ⇒ EventBridgePublisher

@description: Instantiates an EventBridgePublisher ready for testing. AWS and DataDog info is faked. Note that this sets the

metrics object for the class to be a stub. The AWS EventBridge gem will never actually be called as the gem's
#put_events method is replaced with a stub.

Parameters:

  • : (batch_size)

    The number of events to send per batch.

  • : (stub_responses)

    Responses to stub, eg. { put_events: { failed_entry_count: 0, entries: [{ event_id: “1” }, { event_id: “2” }] } }

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/tpt/rails/event_bridge_test_helper.rb', line 11

def self.publisher(batch_size: 10, stub_responses: {})
  Tpt::Rails::EventBridgePublisher.set_metrics(
    Datadog::Statsd.new('localhost', 8125)
  )

  Tpt::Rails::EventBridgePublisher.new(
    event_source: ENV.fetch('TPT_EVENT_SOURCE', 'test-source'),
    batch_size: batch_size,
    client_options: {
      access_key_id: '1234',
      secret_access_key: 'abcd',
      stub_responses: stub_responses
    }
  )
end