devices_updates_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Subscriptions::User::Current::DevicesUpdates, type: :graphql do
  4. let(:subscription) do
  5. <<~QUERY
  6. subscription userCurrentDevicesUpdates {
  7. userCurrentDevicesUpdates {
  8. devices {
  9. name
  10. }
  11. }
  12. }
  13. QUERY
  14. end
  15. let(:mock_channel) { build_mock_channel }
  16. let(:target) { create(:agent) }
  17. context 'with authenticated user', authenticated_as: :target do
  18. it 'subscribes' do
  19. gql.execute(subscription, context: { channel: mock_channel })
  20. expect(gql.result.data).to eq({ 'devices' => nil })
  21. end
  22. it 'receives user device updates for target user' do
  23. gql.execute(subscription, context: { channel: mock_channel })
  24. create(:user_device, user_id: target.id)
  25. expect(mock_channel.mock_broadcasted_messages.first[:result]['data']['userCurrentDevicesUpdates']['devices'].count).to eq(1)
  26. end
  27. it 'does not receive user device updates for other users' do
  28. gql.execute(subscription, context: { channel: mock_channel })
  29. create(:user_device, user_id: create(:agent).id)
  30. expect(mock_channel.mock_broadcasted_messages).to be_empty
  31. end
  32. end
  33. end