list_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::Ticket::Article::List do
  4. subject(:service) { described_class.new(current_user: user) }
  5. let(:ticket) { create(:ticket) }
  6. let(:articles) { create_list(:ticket_article, 3, ticket: ticket) }
  7. describe '#execute' do
  8. before do
  9. articles.first.update!(internal: true)
  10. end
  11. context 'when user has read access (agent)' do
  12. let(:user) { create(:agent, groups: [ticket.group]) }
  13. it 'returns all articles' do
  14. expect(service.execute(ticket: ticket)).to eq(articles)
  15. end
  16. end
  17. context 'when user has no read access (agent)' do
  18. let(:user) { create(:agent) }
  19. it 'returns all articles' do
  20. expect(service.execute(ticket: ticket)).to eq(articles[1..])
  21. end
  22. end
  23. context 'when user has no read access (customer)' do
  24. let(:user) { create(:customer) }
  25. before do
  26. ticket.update!(customer: user)
  27. end
  28. it 'returns only public articles' do
  29. expect(service.execute(ticket: ticket)).to eq(articles[1..])
  30. end
  31. end
  32. end
  33. end