triggers_subscriptions_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Taskbar::TriggersSubscriptions, :aggregate_failures do
  4. let(:taskbar) { create(:taskbar, user: create(:user)) }
  5. let(:related_taskbar) { create(:taskbar, key: taskbar.key, user: create(:user)) }
  6. gqs = Gql::Subscriptions
  7. gqs_uc = gqs::User::Current
  8. before do
  9. freeze_time
  10. related_taskbar.save!
  11. taskbar.save!
  12. travel(1.second)
  13. allow(gqs::TicketLiveUserUpdates).to receive(:trigger)
  14. allow(gqs_uc::TaskbarItemUpdates).to receive(:trigger_after_create)
  15. allow(gqs_uc::TaskbarItemUpdates).to receive(:trigger_after_update)
  16. allow(gqs_uc::TaskbarItemUpdates).to receive(:trigger_after_destroy)
  17. allow(gqs_uc::TaskbarItemStateUpdates).to receive(:trigger)
  18. end
  19. context 'when creating a record' do
  20. it 'triggers correctly' do
  21. create(:taskbar)
  22. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).once
  23. expect(gqs_uc::TaskbarItemUpdates).to have_received(:trigger_after_create).once
  24. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  25. end
  26. end
  27. context 'when updating prio' do
  28. it 'triggers correctly' do
  29. taskbar.prio += 1
  30. taskbar.save!
  31. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).exactly(2)
  32. expect(gqs_uc::TaskbarItemUpdates).not_to have_received(:trigger_after_update)
  33. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  34. end
  35. end
  36. context 'when updating last_contact_at' do
  37. it 'triggers correctly' do
  38. taskbar.touch_last_contact!
  39. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).exactly(1) # only for related_taskbar
  40. expect(gqs_uc::TaskbarItemUpdates).not_to have_received(:trigger_after_update)
  41. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  42. end
  43. end
  44. context 'when updating state' do
  45. context 'with desktop app' do
  46. it 'triggers correctly' do
  47. taskbar.state = { 'body' => 'test' }
  48. taskbar.save!
  49. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).exactly(2)
  50. expect(gqs_uc::TaskbarItemUpdates).to have_received(:trigger_after_update).once # only for taskbar
  51. expect(gqs_uc::TaskbarItemStateUpdates).to have_received(:trigger).once
  52. end
  53. end
  54. context 'with mobile app' do
  55. let(:taskbar) { create(:taskbar, app: 'mobile') }
  56. it 'triggers correctly' do
  57. taskbar.state = { 'body' => 'test' }
  58. taskbar.save!
  59. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).exactly(2)
  60. expect(gqs_uc::TaskbarItemUpdates).to have_received(:trigger_after_update).once # only for taskbar
  61. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  62. end
  63. end
  64. end
  65. context 'when deleting the record' do
  66. it 'triggers correctly' do
  67. taskbar.destroy!
  68. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).once # only for related_taskbar
  69. expect(gqs_uc::TaskbarItemUpdates).to have_received(:trigger_after_destroy)
  70. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  71. end
  72. end
  73. end