change_visibility_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::Ticket::Article::ChangeVisibility do
  4. subject(:service) { described_class.new(current_user: user) }
  5. let(:article) { create(:ticket_article, internal: internal) }
  6. describe '#execute' do
  7. context 'when user has access' do
  8. let(:user) { create(:agent, groups: [article.ticket.group]) }
  9. context 'when public' do
  10. let(:internal) { false }
  11. it 'sets to internal' do
  12. expect { service.execute(article: article, internal: true) }
  13. .to change(article, :internal).to(true)
  14. end
  15. end
  16. context 'when internal' do
  17. let(:internal) { true }
  18. it 'sets to public' do
  19. expect { service.execute(article: article, internal: false) }
  20. .to change(article, :internal).to(false)
  21. end
  22. end
  23. end
  24. context 'when user has no access' do
  25. let(:user) { create(:customer) }
  26. let(:internal) { false }
  27. it 'fails with Pundit error' do
  28. expect { service.execute(article: article, internal: true) }
  29. .to raise_error(Pundit::NotAuthorizedError)
  30. end
  31. end
  32. end
  33. end