isa0060/serio1/input1
     ˆÉÈÇ523ÆÅÄ     ‹      Å•_oÚ0Åßû)<?ì�\ ”‰ÖÉÔ¤¡Q@4Ó6MÓdbC¼%qdß–¶Ÿ~	IWŠ`ë&DŸâ?Ç'çw¯³WÁ¤~™ÈûðrD¦ß�†}B ŸÜ>@ÕFÇi¶ cJhŒ˜Ÿ¬V+gå:Ú,!œAŒiÒ‹FEèÔ?aåšBX,¹(ž„¡ÂDúÃLÈ[¢ô5Z%d³÷<M¹€Lù=Õâ:‘r•)BYdP�,¼ 6cs-îÊw´þË¯8¶ÄçkÛrh|†1¹á‰ZfE�SŸ©tI¬‰<
*Ò™…yÂ³ŸÎR-(á	zôë°?ùVè ãò´Ï8‰�\xômßŸO¼ê�y*ðÝšËJ3âIS-”{ÅW•øJÝï7*M mdTŽJg�R(7Q#�Øœ¬§Al6U•Dü­<zRŒéÅl0ƒá¬*‰(-Ó=«;ÔŸr#3$�22Bmîêü•Ùëlnóó‡)©ÓµŒ‘ú„4ÈNå? ¡¼ÅM¤ðs¸f�Öùa©ÿ0ÚÌ¹¬ÝlwÍ^£Ý%ÍÞ™ë²� Óûp\iÓÆÜè••fƒæéêaÈÞ™L8ø›§„Âí™B©…ÜhL==Kë%Xr£Å6P½vªSÇ}Á/hnÇÖaÿÔ¹gþà¡¾ú¬/RÕeý^6ì    $   ˆÉÈÇ505Æa–ßi~” T¾R( 	Å‚À´¦-ÿÅ ù    ‹      µT]oÓ0}ß¯¸ø�·ä6ý@°9A£©DE×V]Bˆ7vo©ÙîÊøõ8MÑjãã%ñMÎ=9ç\åÒgél¸ü8ÁÛåÕæïßLÆC â‡Þ1]¦Í‹~Ø‰GS¤p®:GÜívá®j“ãr�…Û”}´ÎÈÌ…Üq’œÑúYr´Œû;P'])’±ââè5 Þ:+¹èãÖ´3•æâÆ¢´ÁÖ”V0“3lc)6Ýž„t¥ù}ý�è�9}ë^[í©ë£I¨+àŽ•2W1qº"	•›¬Éb‚2ÓÊâªdê6Ìåš +]L>�‡³Ï‡®¨»Ê 0b“×Ãxz1‹/I2eA‘Ç\5˜	³6šËµü$øº_Ë¯§	Ó“
›Y9©Õ½Å¶ÕL—¶bÞëÀ;(LÕ@ø¯Ò`ÙaÌ/£é2/šHxMñ î‘	‘dî+å •FdN›ûƒê†â¹ZÙêâ{	MFæ…#	@ G‘O0²U·JïTÛ‹Ïé¨‹Ê{f¹o¬V$iWmÉ?iìvºQEA§Ñà¼÷à0
ïþÖÌZ—\˜¶—S)åÊG__×Þ:¯‚îËZ{gpRû¿Ä“´ÂýûÓÿ÷ð›ÿ¶
Åýž¢ØìÃo‰ô-r       ˆÊÉÈ483Ç¾Å ã    ‹      ­”]o›0†ïû+<_ìNÈ‡¦µÆS‘)M¢”j›¦ir°^‰�lgi÷ëgBªÒ)Y÷u…mÞóò>äE:O²�‹1z—]MÑâæít’  ¼$ i–¶7†a/Ï0Â¥sõ9Àn·wƒP›²%”nSÁ:#srÇ1=#Í=C¤Œû+"NºJÐ‰ââé5½uVr1„­5`Kf(ÍÅ—�æÛJX��RØ@¯	´µÞvd¥ù}ó”è/}á>[í�›¥¡Ä•è«d¡bìt�)‘›Y“Çd®•…UÅÔmXÈ5F¬r1þ4IæŸ½\ÙTSÂPiÄ:Æo’xv1�/1�±� ÀŽk®ZÍ”Y‡|L¹–‚Ÿ_·âkùý´aÚjRas#k'µz”‚Gì¢æº²5ó¬#OPš®ª•ðçºÁò'ÍX\.Ç³,�,Û–ðÆâ1Ý³ïÓ…?S¥ÒˆÜisÈÞ½T+[_<lÑ!™‘Eé0E(@G•€³U·JïT—Èwë(KíÉY!Â¯V+L»»näŸ2ö{ý~EA¿‡¢Áù¨�Ð	áðÕë†qâÎuI²ÙQ’ýPøä˜>¬þA4ü‚à7¿A8L'�ý´hÿ)? Ç¢ö¶    D   ˆl–Ðz¾”ªC]Šq@=q¦®41hß�þ_Ë8Ø�@	þÄƒN‹É_�uÐb&=LyZËcõÀÇ 	¨    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe Gql::Subscriptions::UserUpdates, type: :graphql do

  let(:subscription) do
    <<~QUERY
      subscription userUpdates($userId: ID!, $initial: Boolean = false) {
        userUpdates(userId: $userId, initial: $initial) {
          user {
            id
            firstname
            lastname
          }
        }
      }
    QUERY
  end
  let(:mock_channel) { build_mock_channel }
  let(:target)       { create(:user) }
  let(:variables)    { { userId: gql.id(target) } }

  before do
    gql.execute(subscription, variables: variables, context: { channel: mock_channel })
  end

  context 'with authenticated user', authenticated_as: :agent do
    let(:agent) { create(:agent) }

    it 'subscribes' do
      expect(gql.result.data).to eq({ 'user' => nil })
    end

    context 'with initial data' do
      let(:variables) { { userId: gql.id(target), initial: true } }

      it 'subscribes with initial data' do
        expect(gql.result.data[:user][:firstname]).to eq(target.firstname)
      end
    end

    it 'receives user updates for target user' do
      target.save!
      expect(mock_channel.mock_broadcasted_messages.first[:result]['data']['userUpdates']['user']['firstname']).to eq(target.firstname)
    end

    it 'does not receive user updates for other users' do
      create(:agent).save!
      expect(mock_channel.mock_broadcasted_messages).to be_empty
    end
  end

  context 'with authenticated customer', authenticated_as: :customer do
    let(:customer) { create(:customer) }

    context 'when subscribing for other users' do
      it 'does not subscribe but returns an authorization error' do
        expect(gql.result.error_type).to eq(Exceptions::Forbidden)
      end
    end

    context 'when subscribing for itself' do
      let(:target) { customer }

      it 'subscribes' do
        expect(gql.result.data).to eq({ 'user' => nil })
      end

      it 'receives user updates for target user' do
        target.save!
        expect(mock_channel.mock_broadcasted_messages.first[:result]['data']['userUpdates']['user']['firstname']).to eq(target.firstname)
      end

      it 'does not receive user updates for other users' do
        create(:agent).save!
        expect(mock_channel.mock_broadcasted_message