Sha256: 9a301b1a2230c3406b29ff561bb0dc9966c32a36f34be90e874edcb56be22cbc

Contents?: true

Size: 1.83 KB

Versions: 16

Compression:

Stored size: 1.83 KB

Contents

module SubscriptionHelpers
  def self_serve_subscription(
    schema: NulogyMessageBusProducer::Specs::TestSchema,
    subscription_id: SecureRandom.uuid,
    **query_args
  )
    gql = subscription_query(subscription_id: subscription_id, **query_args)

    expect {
      gql_response = execute_graphql(gql, schema)
      expect(gql_response).to eq(data: {})
    }.to change(NulogyMessageBusProducer::SelfServeSubscription, :count).by(1)

    NulogyMessageBusProducer::SelfServeSubscription.find(subscription_id)
  end

  def configured_subscription(
    schema: NulogyMessageBusProducer::Specs::TestSchema,
    subscription_id: SecureRandom.uuid,
    subscription_group_id: SecureRandom.uuid,
    **query_args
  )
    gql = subscription_query(
      subscription_id: subscription_id,
      subscription_group_id: subscription_group_id,
      **query_args
    )

    NulogyMessageBusProducer.config.add_subscription!(
      schema: schema.name,
      query: gql
    )
  end

  def subscription_query(
    event_type: "testCreated",
    query: "foo { id }",
    subscription_id: SecureRandom.uuid,
    subscription_group_id: SecureRandom.uuid,
    topic_name: "some_topic"
  )
    <<~GRAPHQL
      subscription {
        #{event_type} (
          subscriptionId: "#{subscription_id}",
          subscriptionGroupId: "#{subscription_group_id}",
          topicName: "#{topic_name}"
        ) {
          #{query}
        }
      }
    GRAPHQL
  end

  def execute_graphql(query, schema, variables: {}, context: {})
    response = schema.execute(
      query,
      variables: variables,
      context: context,
      operation_name: nil
    )

    response.to_h.deep_symbolize_keys
  end

  def trigger_event(event_type, root_object)
    schema = NulogyMessageBusProducer::Specs::TestSchema
    NulogyMessageBusProducer.trigger_event(schema, event_type, root_object)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
nulogy_message_bus_producer-5.0.8 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.7 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.6 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.5 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.4 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.3 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.2 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.1 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.1.alpha spec/support/subscription_helpers.rb
nulogy_message_bus_producer-5.0.0 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-4.0.0 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-3.7.0 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-3.6.0 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-3.5.0 spec/support/subscription_helpers.rb
nulogy_message_bus_producer-4.0.0.alpha spec/support/subscription_helpers.rb
nulogy_message_bus_producer-3.4.1 spec/support/subscription_helpers.rb