triggers_subscriptions_spec.rb 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::TriggersSubscriptions do
  4. let(:ticket) { create(:ticket) }
  5. describe '#trigger_subscriptions' do
  6. before do
  7. allow(Gql::Subscriptions::TicketUpdates).to receive(:trigger)
  8. end
  9. it 'triggers ticket updates subscription when ticket is updated' do
  10. ticket.update title: 'new title'
  11. expect(Gql::Subscriptions::TicketUpdates)
  12. .to have_received(:trigger)
  13. .with(ticket, arguments: { ticket_id: ticket.to_global_id.to_s })
  14. end
  15. end
  16. describe '#trigger_checklist_subscriptions', :aggregate_failures, current_user_id: 1 do
  17. let(:own_checklist) { create(:checklist, ticket:) }
  18. let(:referenced_checklist) { create(:checklist).tap { |elem| elem.items.create! ticket: } }
  19. let(:other_referenced_checklist) { create(:checklist).tap { |elem| 5.times { elem.items.create! ticket: } } }
  20. before do
  21. own_checklist
  22. referenced_checklist
  23. other_referenced_checklist
  24. allow(Gql::Subscriptions::Ticket::ChecklistUpdates).to receive(:trigger)
  25. end
  26. it 'triggers checklist update ticket is tracked in on title change' do
  27. ticket.update title: 'new title'
  28. expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
  29. .to have_received(:trigger)
  30. .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
  31. end
  32. it 'triggers checklist update ticket is tracked in on group change' do
  33. ticket.update group: create(:group)
  34. expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
  35. .to have_received(:trigger)
  36. .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
  37. end
  38. it 'triggers checklist update ticket is tracked in on state change' do
  39. ticket.update state: Ticket::State.find_by(name: 'closed')
  40. expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
  41. .to have_received(:trigger)
  42. .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
  43. end
  44. it 'triggers checklist update ticket is tracked in twice on state and group change' do
  45. ticket.update state: Ticket::State.find_by(name: 'closed'), group: create(:group)
  46. expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
  47. .to have_received(:trigger)
  48. .with(referenced_checklist, arguments: { ticket_id: referenced_checklist.ticket.to_global_id.to_s })
  49. .twice
  50. end
  51. it 'triggers checklist update once per checklist' do
  52. ticket.update title: 'new title'
  53. expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
  54. .to have_received(:trigger)
  55. .twice
  56. end
  57. it 'does not trigger update checklist ticket is tracked in on other change' do
  58. ticket.update owner: create(:agent)
  59. expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
  60. .not_to have_received(:trigger)
  61. .with(referenced_checklist, any_args)
  62. end
  63. it 'does not trigger update for checklist of the ticket that was changed' do
  64. ticket.update owner: create(:agent)
  65. expect(Gql::Subscriptions::Ticket::ChecklistUpdates)
  66. .not_to have_received(:trigger)
  67. .with(own_checklist, any_args)
  68. end
  69. end
  70. end