push_messages_spec.rb 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Subscriptions::PushMessages, type: :graphql do
  4. let(:subscription) do
  5. <<~QUERY
  6. subscription pushMessages {
  7. pushMessages {
  8. title
  9. text
  10. }
  11. }
  12. QUERY
  13. end
  14. let(:mock_channel) { build_mock_channel }
  15. let(:expected_msg) do
  16. {
  17. result: {
  18. 'data' => {
  19. 'pushMessages' => {
  20. 'title' => 'Attention',
  21. 'text' => 'Maintenance test message.',
  22. }
  23. }
  24. },
  25. more: true,
  26. }
  27. end
  28. def trigger_push_message(title, text)
  29. described_class.trigger({ title: title, text: text })
  30. end
  31. before do
  32. gql.execute(subscription, context: { channel: mock_channel })
  33. end
  34. it 'broadcasts push message to all users' do
  35. trigger_push_message('Attention', 'Maintenance test message.')
  36. expect(mock_channel.mock_broadcasted_messages).to eq([expected_msg])
  37. end
  38. end