user_context_spec.rb 1.0 KB

123456789101112131415161718192021222324252627
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe UserContext do
  4. subject(:user_context) { described_class.new(user, token) }
  5. describe '#permissions?' do
  6. context 'when user with ticket.agent permission' do
  7. let(:user) { create(:user, roles: create_list(:role, 1, :agent)) }
  8. let(:token) { nil }
  9. it { is_expected.to be_permissions('ticket.agent') }
  10. it { is_expected.not_to be_permissions('admin') }
  11. end
  12. # https://github.com/zammad/zammad/issues/3186
  13. context 'when user with ticket.agent permission and token created by user who doesn\'t' do
  14. let(:user) { create(:user, roles: create_list(:role, 1, :agent)) }
  15. let(:token_owner) { create(:user, roles: create_list(:role, 1, :admin)) }
  16. let(:token) { create(:token, user: token_owner, preferences: { permission: %w[ticket.agent] }) }
  17. it { is_expected.to be_permissions('ticket.agent') }
  18. it { is_expected.not_to be_permissions('admin') }
  19. end
  20. end
  21. end