diff options
Diffstat (limited to 'spec/support/helpers/graphql/subscriptions/notes/helper.rb')
-rw-r--r-- | spec/support/helpers/graphql/subscriptions/notes/helper.rb | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/spec/support/helpers/graphql/subscriptions/notes/helper.rb b/spec/support/helpers/graphql/subscriptions/notes/helper.rb new file mode 100644 index 00000000000..9a552f9879e --- /dev/null +++ b/spec/support/helpers/graphql/subscriptions/notes/helper.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +module Graphql + module Subscriptions + module Notes + module Helper + def subscription_response + subscription_channel = subscribe + yield + subscription_channel.mock_broadcasted_messages.first + end + + def notes_subscription(name, noteable, current_user) + mock_channel = Graphql::Subscriptions::ActionCable::MockActionCable.get_mock_channel + + query = case name + when 'workItemNoteDeleted' + note_deleted_subscription_query(name, noteable) + when 'workItemNoteUpdated' + note_updated_subscription_query(name, noteable) + when 'workItemNoteCreated' + note_created_subscription_query(name, noteable) + else + raise "Subscription query unknown: #{name}" + end + + GitlabSchema.execute(query, context: { current_user: current_user, channel: mock_channel }) + + mock_channel + end + + def note_subscription(name, noteable, current_user) + mock_channel = Graphql::Subscriptions::ActionCable::MockActionCable.get_mock_channel + + query = <<~SUBSCRIPTION + subscription { + #{name}(noteableId: \"#{noteable.to_gid}\") { + id + body + } + } + SUBSCRIPTION + + GitlabSchema.execute(query, context: { current_user: current_user, channel: mock_channel }) + + mock_channel + end + + private + + def note_deleted_subscription_query(name, noteable) + <<~SUBSCRIPTION + subscription { + #{name}(noteableId: \"#{noteable.to_gid}\") { + id + discussionId + lastDiscussionNote + } + } + SUBSCRIPTION + end + + def note_created_subscription_query(name, noteable) + <<~SUBSCRIPTION + subscription { + #{name}(noteableId: \"#{noteable.to_gid}\") { + id + discussion { + id + notes { + nodes { + id + } + } + } + } + } + SUBSCRIPTION + end + + def note_updated_subscription_query(name, noteable) + <<~SUBSCRIPTION + subscription { + #{name}(noteableId: \"#{noteable.to_gid}\") { + id + body + } + } + SUBSCRIPTION + end + end + end + end +end |