0
  -   'ˆÍ�þd	q°9 €)P;üÿØƒe–Ü×_�uÐb&=LyZËcõÆÖ     '# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe Ticket::TriggersSubscriptions do
  let(:ticket) { create(:ticket) }

  describe '#trigger_subscriptions' do
    before do
      allow(Gql::Subscriptions::TicketUpdates).to receive(:trigger)
    end

    it 'triggers ticket updates subscription when ticket is updated' do
      ticket.update title: 'new title'

      expect(Gql::Subscriptions::TicketUpdates)
        .to have_received(:trigger)
        .with(ticket, arguments: { ticket_id: ticket.to_global_id.to_s })
    end
  end

  describe '#trigger_checklist_subscriptions', :aggregate_failures, current_user_id: 1 do
    let(:own_checklist)              { create(:checklist, ticket:) }
    let(:referenced_checklist)       { create(:checklist).tap { |elem| elem.items.create! ticket: } }
    let(:other_referenced_checklist) { create(:checklist).tap { |elem| 5.times { elem.items.create! ticket: } } }

    before do
      own_checklist
      referenced_checklist
      other_referenced_checklist

      allow(Gql::Subscriptions::Ticket::ChecklistUpdates).to receive(:trigger)
    end

    it 'triggers checklist update ticket is tracked in on title change' do
      ticket.update title: 'new title'

      expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
        .to have_received(:trigger)
        .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
    end

    it 'triggers checklist update ticket is tracked in on group change' do
      ticket.update group: create(:group)

      expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
        .to have_received(:trigger)
        .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
    end

    it 'triggers checklist update ticket is tracked in on state change' do
      ticket.update state: Ticket::State.find_by(name: 'closed')

      expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
        .to have_received(:trigger)
        .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
    end

    it 'triggers checklist update ticket is tracked in twice on state and group change' do
      ticket.update state: Ticket::State.find_by(name: 'closed'), group: create(:group)

      expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
        .to have_received(:trigger)
        .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
        .twice
    end

    it 'triggers checklist update once per checklist' do
      ticket.update title: 'new title'

      expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
        .to have_received(:trigger)
        .twice
    end

    it 'does not trigger update checklist ticket is tracked in on other change' do
      ticket.update owner: create(:agent)

      expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
        .not_to have_received(:trigger)
        .with(referenced_checklist, any_args)
    end

    it 'does not trigger update for checklist of the ticket that was changed' do
      ticket.update owner: create(:agent)

      expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
        .not_to have_received(:trigger)
        .with(own_checklist, any_args)
    end
  end
end
  $   )ˆÕÔØ543Óa–ßi~” T¾R( 	Å �µp,©‹Fÿ×     )‹      ½•Qo›0…ßû+<?ì-ÜHWµÀÔ…J‹–&QÊ´MÓ„0ÁÁÈÜ6É~ýL ›’®•²<á‡ãó]®óÆŸ‚oÓò1¸‘éç£á€ÐÀk à~ýÀ6º&ÀÍ˜š"— «ÕÊXY†Tf�â2³¡D%"4bŒ©wæT÷¼3â¤œÅúJ˜qo˜Ç|MdB@Þc)bnÃ}© s(6˜ÊÜ2Lw Ökh,œ¹Œ7•³ù
-ÞnÎæ[³j©<SòÀ2±È]Š² ž#–RªÈ¥ "™—0ÏXþÓXˆ„–¡K¿“Z˜Vo{#©â‰KßÜñÕÄ½¦Þ˜-õ~l¿æ¶ÖŒX‰d)c‘ßi±O½;ñë°¡_ú¼Œ”(PÈ|'�ØF�dVL³ö5AªÚªZÿ«,ú£ÓëÙÍ8ð‡³º%qe±K÷ì™PoÊÏ‘øBñ¥Ú4¹k“·ù¼,®KÒ¤Rb‘"õé�½ÊW $2‹¹jÃÂÃb±(åa¨S·«vâ¿"öº½óŽÙít/ˆi_Ú!ÿ‘ùÛ$Á×`?IÄJžˆµQl4È®x	Ç»ŠÃêäèÖ§Óqh5²Ë†¤U‡åât,¡È†aM²+ŽÁAÌóSžÉ²™þ¤š#yªŽBÒëŸŽ¤`ª|äxZ…Â6Ÿ¡xá�šæÀv:PØß‚CrØÃ       +ˆÖÕÙ483Ô¾× ã    +‹      ½”a�Ò0Çßß§¨}á;ö†šÜu5'#‘ÈáfÔCºµlc