macros_update_spec.rb 973 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Subscriptions::MacrosUpdate, type: :graphql do
  4. let(:mock_channel) { build_mock_channel }
  5. let(:subscription) do
  6. <<~QUERY
  7. subscription macrosUpdate {
  8. macrosUpdate {
  9. macroUpdated
  10. }
  11. }
  12. QUERY
  13. end
  14. let(:expected_msg) do
  15. {
  16. result: {
  17. 'data' => {
  18. 'macrosUpdate' => {
  19. 'macroUpdated' => true
  20. }
  21. }
  22. },
  23. more: true
  24. }
  25. end
  26. before do
  27. gql.execute(subscription, context: { channel: mock_channel })
  28. end
  29. context 'when authenticated', authenticated_as: :agent do
  30. let(:agent) { create(:agent) }
  31. it 'creating a macro triggers subscription' do
  32. create(:macro)
  33. expect(mock_channel.mock_broadcasted_messages).to eq([expected_msg])
  34. end
  35. end
  36. it_behaves_like 'graphql responds with error if unauthenticated'
  37. end