updates_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Subscriptions::User::Current::RecentView::Updates, authenticated_as: :agent, type: :graphql do
  4. let(:mock_channel) { build_mock_channel }
  5. let(:agent) { create(:agent) }
  6. let(:subscription) do
  7. <<~QUERY
  8. subscription userCurrentRecentViewUpdates {
  9. userCurrentRecentViewUpdates {
  10. recentViewsUpdated
  11. }
  12. }
  13. QUERY
  14. end
  15. before do
  16. gql.execute(subscription, context: { channel: mock_channel })
  17. end
  18. context 'when subscribed' do
  19. it 'subscribes' do
  20. expect(gql.result.data).to eq({ 'recentViewsUpdated' => nil })
  21. end
  22. it 'receives recent_view updates for the current user' do
  23. RecentView.log('User', agent.id, agent)
  24. expect(mock_channel.mock_broadcasted_messages.first.dig(:result, 'data', 'userCurrentRecentViewUpdates', 'recentViewsUpdated')).to be(true)
  25. end
  26. context 'when another user creates updates' do
  27. let(:other_user) { create(:agent) }
  28. it 'does not receive recent_view updates for another user' do
  29. UserInfo.current_user_id = other_user.id # Required to set created_by_id to this user.
  30. RecentView.log('User', agent.id, other_user)
  31. expect(mock_channel.mock_broadcasted_messages).to be_empty
  32. end
  33. end
  34. end
  35. end