1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
# frozen_string_literal: true
require "spec_helper"
describe GraphQL::Tracing::NotificationsTracing do
module NotificationsTracingTest
class Query < GraphQL::Schema::Object
field :int, Integer, null: false
def int
1
end
end
class Schema < GraphQL::Schema
query Query
end
end
describe "Observing" do
it "dispatchs the event to the notifications engine with suffixed key" do
dispatched_events = trigger_fake_notifications_tracer(NotificationsTracingTest::Schema)
assert dispatched_events.length > 0
dispatched_events.each do |event, payload|
assert event.end_with?(".graphql")
assert payload.is_a?(Hash)
end
end
end
def trigger_fake_notifications_tracer(schema)
dispatched_events = []
engine = Object.new
engine.define_singleton_method(:instrument) do |event, payload, &blk|
dispatched_events << [event, payload]
blk.call if blk
end
tracer = GraphQL::Tracing::NotificationsTracing.new(engine)
schema.tracer(tracer)
schema.execute "query X { int }"
dispatched_events
end
end
|