triggers_subscriptions_spec.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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).not_to have_received(:trigger)
  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 active' do
  37. it 'triggers correctly' do
  38. taskbar.active = !taskbar.active
  39. taskbar.save!
  40. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).twice
  41. expect(gqs_uc::TaskbarItemUpdates).not_to have_received(:trigger_after_update)
  42. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  43. end
  44. end
  45. context 'when updating dirty' do
  46. it 'triggers correctly' do
  47. taskbar.preferences[:dirty] = !taskbar.preferences[:dirty]
  48. taskbar.save!
  49. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).twice
  50. expect(gqs_uc::TaskbarItemUpdates).to have_received(:trigger_after_update).once
  51. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  52. end
  53. end
  54. context 'when updating last_contact_at' do
  55. it 'triggers correctly' do
  56. taskbar.touch_last_contact!
  57. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).exactly(1) # only for related_taskbar
  58. expect(gqs_uc::TaskbarItemUpdates).not_to have_received(:trigger_after_update)
  59. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  60. end
  61. end
  62. context 'when updating state' do
  63. context 'with desktop app' do
  64. it 'triggers correctly' do
  65. taskbar.state = { 'body' => 'test' }
  66. taskbar.save!
  67. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).exactly(2)
  68. expect(gqs_uc::TaskbarItemStateUpdates).to have_received(:trigger).once
  69. end
  70. end
  71. context 'with mobile app' do
  72. let(:taskbar) { create(:taskbar, app: 'mobile') }
  73. it 'triggers correctly' do
  74. taskbar.state = { 'body' => 'test' }
  75. taskbar.save!
  76. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).exactly(2)
  77. expect(gqs_uc::TaskbarItemUpdates).not_to have_received(:trigger_after_update)
  78. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  79. end
  80. end
  81. end
  82. context 'when deleting the record' do
  83. it 'triggers correctly' do
  84. taskbar.destroy!
  85. expect(gqs::TicketLiveUserUpdates).to have_received(:trigger).once # only for related_taskbar
  86. expect(gqs_uc::TaskbarItemUpdates).to have_received(:trigger_after_destroy)
  87. expect(gqs_uc::TaskbarItemStateUpdates).not_to have_received(:trigger)
  88. end
  89. end
  90. end