ticket_overview_updates_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Subscriptions::TicketOverviewUpdates, authenticated_as: :agent, type: :graphql do
  4. let(:mock_channel) { build_mock_channel }
  5. let(:overview) { create(:overview) }
  6. let(:agent) { create(:agent) }
  7. let(:subscription) do
  8. <<~QUERY
  9. subscription ticketOverviewUpdates {
  10. ticketOverviewUpdates {
  11. ticketOverviews {
  12. edges {
  13. node {
  14. id
  15. name
  16. }
  17. }
  18. }
  19. }
  20. }
  21. QUERY
  22. end
  23. before do
  24. overview
  25. gql.execute(subscription, context: { channel: mock_channel })
  26. end
  27. context 'when subscribed' do
  28. it 'subscribes' do
  29. expect(gql.result.data).to eq({ 'ticketOverviews' => nil })
  30. end
  31. it 'receives ticket overview updates' do
  32. overview.update!(name: 'example overview')
  33. expect(mock_channel.mock_broadcasted_messages.first.dig(:result, 'data', 'ticketOverviewUpdates', 'ticketOverviews', 'edges').first['node']['name']).to eq('example overview')
  34. end
  35. it 'receives updates whenever a ticket overview was created' do
  36. create(:overview)
  37. # We have 7 default overviews + the one we created in the before block.
  38. expect(mock_channel.mock_broadcasted_messages.first.dig(:result, 'data', 'ticketOverviewUpdates', 'ticketOverviews', 'edges').size).to eq(9)
  39. end
  40. it 'receives updates whenever a ticket overview was deleted' do
  41. overview.destroy!
  42. # We have 7 default overviews + the one we created in the before block.
  43. expect(mock_channel.mock_broadcasted_messages.first.dig(:result, 'data', 'ticketOverviewUpdates', 'ticketOverviews', 'edges').size).to eq(7)
  44. end
  45. end
  46. end