overviews_spec.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. require 'rails_helper'
  2. RSpec.describe Ticket::Overviews do
  3. describe '.all' do
  4. let(:views) { described_class.all(current_user: current_user).map(&:name) }
  5. shared_examples 'containing' do |overview|
  6. it "returns #{overview}" do
  7. expect(views).to include(overview)
  8. end
  9. end
  10. shared_examples 'not containing' do |overview|
  11. it "doesn't return #{overview}" do
  12. expect(views).not_to include(overview)
  13. end
  14. end
  15. context 'when Agent' do
  16. let(:current_user) { create(:agent) }
  17. it_behaves_like 'containing', 'Open'
  18. it_behaves_like 'not containing', 'My Tickets'
  19. it_behaves_like 'not containing', 'My Organization Tickets'
  20. end
  21. context 'when Agent is also Customer' do
  22. let(:current_user) { create(:agent_and_customer, :with_org) }
  23. it_behaves_like 'containing', 'Open'
  24. it_behaves_like 'containing', 'My Tickets'
  25. it_behaves_like 'containing', 'My Organization Tickets'
  26. end
  27. context 'when Customer' do
  28. let(:current_user) { create(:customer, :with_org) }
  29. it_behaves_like 'not containing', 'Open'
  30. it_behaves_like 'containing', 'My Tickets'
  31. it_behaves_like 'containing', 'My Organization Tickets'
  32. end
  33. end
  34. describe '.index' do
  35. # https://github.com/zammad/zammad/issues/1769
  36. it 'does not return multiple results for a single ticket' do
  37. user = create(:user)
  38. source_ticket = create(:ticket, customer: user, created_by_id: user.id)
  39. source_ticket2 = create(:ticket, customer: user, created_by_id: user.id)
  40. # create some articles
  41. create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf1@blubselector.de', created_by_id: user.id)
  42. create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf2@blubselector.de', created_by_id: user.id)
  43. create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf3@blubselector.de', created_by_id: user.id)
  44. create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf3@blubselector.de', created_by_id: user.id)
  45. create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf4@blubselector.de', created_by_id: user.id)
  46. create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf5@blubselector.de', created_by_id: user.id)
  47. condition = {
  48. 'article.from' => {
  49. operator: 'contains',
  50. value: 'blubselector.de',
  51. },
  52. }
  53. overview = create(:overview, condition: condition)
  54. result = described_class.index(user)
  55. result = result.select { |x| x[:overview][:name] == overview.name }
  56. expect(result.count).to be == 1
  57. expect(result[0][:count]).to be == 2
  58. expect(result[0][:tickets].count).to be == 2
  59. end
  60. end
  61. describe 'Mentions:' do
  62. let(:group_read) { create(:group) }
  63. let(:user_read) { create(:agent) }
  64. let(:ticket) { create(:ticket, group: group_read) }
  65. before do
  66. user_read.group_names_access_map = {
  67. group_read.name => 'read',
  68. }
  69. end
  70. it 'does show read only tickets in overview because user is mentioned' do
  71. create(:mention, mentionable: ticket, user: user_read)
  72. result = described_class.index(user_read, ['my_subscribed_tickets'])
  73. expect(result.first[:tickets].pluck(:id)).to eq([ticket.id])
  74. end
  75. it 'does not show read only tickets in overview' do
  76. result = described_class.index(user_read, ['my_subscribed_tickets'])
  77. expect(result.first[:tickets]).to eq([])
  78. end
  79. end
  80. end