shared_draft_zoom_policy_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe Ticket::SharedDraftZoomPolicy do
  4. subject { described_class.new(user, record) }
  5. let(:ticket) { create(:ticket) }
  6. let(:record) { create(:ticket_shared_draft_zoom, ticket: ticket) }
  7. let(:user) { create(:agent) }
  8. shared_examples 'access allowed' do
  9. it { is_expected.to be_update }
  10. it { is_expected.to be_show }
  11. it { is_expected.to be_destroy }
  12. end
  13. shared_examples 'access denied' do
  14. it { is_expected.not_to be_update }
  15. it { is_expected.not_to be_show }
  16. it { is_expected.not_to be_destroy }
  17. end
  18. context 'when user has no tickets access' do
  19. let(:user) { create(:customer) }
  20. include_examples 'access denied'
  21. end
  22. context 'when user has ticket access' do
  23. context 'when user has access to the ticket' do
  24. before do
  25. user.user_groups.create! group: ticket.group, access: :full
  26. end
  27. include_examples 'access allowed'
  28. end
  29. context 'when user has read-only access to the ticket' do
  30. before do
  31. user.user_groups.create! group: ticket.group, access: :read
  32. end
  33. include_examples 'access denied'
  34. end
  35. context 'when user has no access to the ticket' do
  36. before do
  37. user.user_groups.create! group: create(:group), access: :full
  38. end
  39. include_examples 'access denied'
  40. end
  41. end
  42. end