overviews_spec.rb 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::Overviews do
  4. describe '.all' do
  5. let(:views) { described_class.all(current_user: current_user).map(&:name) }
  6. shared_examples 'containing' do |overview|
  7. it "returns #{overview}" do
  8. expect(views).to include(overview)
  9. end
  10. end
  11. shared_examples 'not containing' do |overview|
  12. it "doesn't return #{overview}" do
  13. expect(views).not_to include(overview)
  14. end
  15. end
  16. context 'when Agent' do
  17. let(:current_user) { create(:agent) }
  18. it_behaves_like 'containing', 'Open Tickets'
  19. it_behaves_like 'not containing', 'My Tickets'
  20. it_behaves_like 'not containing', 'My Organization Tickets'
  21. end
  22. context 'when Agent is also Customer' do
  23. let(:current_user) { create(:agent_and_customer, :with_org) }
  24. it_behaves_like 'containing', 'Open Tickets'
  25. it_behaves_like 'containing', 'My Tickets'
  26. it_behaves_like 'containing', 'My Organization Tickets'
  27. end
  28. context 'when Customer' do
  29. let(:current_user) { create(:customer, :with_org) }
  30. it_behaves_like 'not containing', 'Open Tickets'
  31. it_behaves_like 'containing', 'My Tickets'
  32. it_behaves_like 'containing', 'My Organization Tickets'
  33. end
  34. end
  35. describe '.index' do
  36. # https://github.com/zammad/zammad/issues/1769
  37. it 'does not return multiple results for a single ticket' do
  38. user = create(:user)
  39. source_ticket = create(:ticket, customer: user, created_by_id: user.id)
  40. source_ticket2 = create(:ticket, customer: user, created_by_id: user.id)
  41. # create some articles
  42. create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf1@blubselector.de', created_by_id: user.id)
  43. create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf2@blubselector.de', created_by_id: user.id)
  44. create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf3@blubselector.de', created_by_id: user.id)
  45. create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf3@blubselector.de', created_by_id: user.id)
  46. create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf4@blubselector.de', created_by_id: user.id)
  47. create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf5@blubselector.de', created_by_id: user.id)
  48. condition = {
  49. 'article.from' => {
  50. operator: 'contains',
  51. value: 'blubselector.de',
  52. },
  53. }
  54. overview = create(:overview, condition: condition)
  55. result = described_class.index(user)
  56. result = result.select { |x| x[:overview][:name] == overview.name }
  57. expect(result.count).to eq(1)
  58. expect(result[0][:count]).to eq(2)
  59. expect(result[0][:tickets].count).to eq(2)
  60. end
  61. # https://github.com/zammad/zammad/issues/3853
  62. context 'with specific group permissions' do
  63. let(:group_read) { create(:group) }
  64. let(:group_overview) { create(:group) }
  65. let(:user) { create(:agent) }
  66. let(:ticket_read) { create(:ticket, group: group_read) }
  67. let(:ticket_overview) { create(:ticket, group: group_overview) }
  68. before do
  69. user.group_names_access_map = {
  70. group_read.name => %w[read],
  71. group_overview.name => %w[read overview],
  72. }
  73. create(:mention, mentionable: ticket_read, user: user)
  74. create(:mention, mentionable: ticket_overview, user: user)
  75. end
  76. it 'displays the correct amount of tickets in the sidebar' do
  77. result = described_class.index(user, ['my_subscribed_tickets'])
  78. expect(result.first[:count]).to eq(2)
  79. end
  80. it 'displays the correct amount of tickets in the list' do
  81. result = described_class.index(user, ['my_subscribed_tickets'])
  82. expect(result.first[:tickets].pluck(:id)).to eq([ticket_read.id, ticket_overview.id])
  83. end
  84. end
  85. end
  86. describe 'Mentions:' do
  87. let(:group_read) { create(:group) }
  88. let(:user_read) { create(:agent) }
  89. let(:ticket) { create(:ticket, group: group_read) }
  90. before do
  91. user_read.group_names_access_map = {
  92. group_read.name => 'read',
  93. }
  94. end
  95. it 'does show read only tickets in overview because user is mentioned' do
  96. create(:mention, mentionable: ticket, user: user_read)
  97. result = described_class.index(user_read, ['my_subscribed_tickets'])
  98. expect(result.first[:tickets].pluck(:id)).to eq([ticket.id])
  99. end
  100. it 'does not show read only tickets in overview' do
  101. result = described_class.index(user_read, ['my_subscribed_tickets'])
  102. expect(result.first[:tickets]).to eq([])
  103. end
  104. end
  105. end