Sha256: 917bf97e166ced76581ac9c8e2068c413887aaa057951a4011e4ea1320b360e6

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require_relative "waterdrop/pact_waterdrop_client"

module PactMessageHelpers
  module ProviderHelpers
    def with_pact_producer
      client = PactWaterdropClient.new
      yield(client)
      client.to_pact
    end

    def produce_outbox_item(item)
      raise "Please require sbmt/kafka_producer to use helper" unless defined?(::Sbmt::KafkaProducer)

      with_pact_producer do |client|
        Sbmt::KafkaProducer::OutboxProducer.new(
          client: client, topic: item.transports.first.topic
        ).call(item, item.payload)
      end
    end
  end

  module ConsumerHelpers
    def outbox_headers
      raise "Please require sbmt/outbox to use helper" unless defined?(::Sbmt::Outbox)

      {
        Sbmt::Outbox::OutboxItem::OUTBOX_HEADER_NAME => match_regex(/(.+?_)*outbox_item/, "order_outbox_item"),
        Sbmt::Outbox::OutboxItem::IDEMPOTENCY_HEADER_NAME => match_uuid,
        Sbmt::Outbox::OutboxItem::SEQUENCE_HEADER_NAME => match_regex(/\d+/, "68"),
        Sbmt::Outbox::OutboxItem::EVENT_TIME_HEADER_NAME => match_iso8601,
        Sbmt::Outbox::OutboxItem::DISPATCH_TIME_HEADER_NAME => match_iso8601
      }
    end
  end
end

RSpec.configure do |config|
  config.extend PactMessageHelpers::ProviderHelpers, pact_entity: :provider
  config.include PactMessageHelpers::ConsumerHelpers, pact_entity: :consumer
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sbmt-pact-0.12.2 lib/sbmt/pact/rspec/support/pact_message_helpers.rb
sbmt-pact-0.12.1 lib/sbmt/pact/rspec/support/pact_message_helpers.rb
sbmt-pact-0.12.0 lib/sbmt/pact/rspec/support/pact_message_helpers.rb