config_updates_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Subscriptions::ConfigUpdates, type: :graphql do
  4. let(:setting) { build(:setting, name: 'broadcast_test', state: setting_value, frontend: true) }
  5. let(:subscription) do
  6. <<~QUERY
  7. subscription configUpdates {
  8. configUpdates {
  9. setting {
  10. key
  11. value
  12. }
  13. }
  14. }
  15. QUERY
  16. end
  17. let(:mock_channel) { build_mock_channel }
  18. let(:expected_msg) do
  19. {
  20. result: {
  21. 'data' => {
  22. 'configUpdates' => {
  23. 'setting' => {
  24. 'key' => 'broadcast_test',
  25. 'value' => expected_value
  26. }
  27. }
  28. }
  29. },
  30. more: true,
  31. }
  32. end
  33. context 'when using static value' do
  34. let(:setting_value) { 'subscription_test' }
  35. let(:expected_value) { setting_value }
  36. it 'broadcasts config update events' do
  37. gql.execute(subscription, context: { channel: mock_channel })
  38. setting.save
  39. expect(mock_channel.mock_broadcasted_messages).to eq([expected_msg])
  40. end
  41. end
  42. context 'when using interpolated value' do
  43. let(:setting_value) { 'test #{config.fqdn}' } # rubocop:disable Lint/InterpolationCheck
  44. let(:expected_value) { "test #{Setting.get('fqdn')}" }
  45. it 'broadcasts config update events with interpolated string' do
  46. gql.execute(subscription, context: { channel: mock_channel })
  47. setting.save
  48. expect(mock_channel.mock_broadcasted_messages).to eq([expected_msg])
  49. end
  50. end
  51. end