online_notification_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/application_model_examples'
  4. RSpec.describe OnlineNotification, type: :model do
  5. subject(:online_notification) { create(:online_notification, o: ticket) }
  6. let(:ticket) { create(:ticket) }
  7. it_behaves_like 'ApplicationModel'
  8. describe '#related_object' do
  9. it 'returns ticket' do
  10. expect(online_notification.related_object).to eq ticket
  11. end
  12. end
  13. describe '.list' do
  14. let(:user) { create(:agent, groups: [group]) }
  15. let(:another_user) { create(:agent, groups: [group]) }
  16. let(:group) { create(:group) }
  17. let(:ticket) { create(:ticket, group: group) }
  18. let(:another_ticket) { create(:ticket, group: group) }
  19. let(:notification_1) { create(:online_notification, o: ticket, user: user) }
  20. let(:notification_2) { create(:online_notification, o: ticket, user: another_user) }
  21. let(:notification_3) { create(:online_notification, o: another_ticket, user: user) }
  22. before do
  23. notification_1 && notification_2 && notification_3
  24. end
  25. it 'returns notifications for a given user' do
  26. expect(described_class.list(user))
  27. .to contain_exactly(notification_1, notification_3)
  28. end
  29. context 'when user looses access to one of the referenced tickets' do
  30. before do
  31. another_ticket.update! group: create(:group)
  32. end
  33. it 'with ensure_access flag it returns notifications given user has access to' do
  34. expect(described_class.list(user, access: 'full'))
  35. .to contain_exactly(notification_1)
  36. end
  37. it 'without ensure_access flag it returns all notifications given user has' do
  38. expect(described_class.list(user, access: 'ignore'))
  39. .to contain_exactly(notification_1, notification_3)
  40. end
  41. end
  42. end
  43. end