session_helper_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe SessionHelper do
  4. describe 'Core Workflow: Does show wrong field list if you only have admin permissions and not ticket.agent permissions #4035' do
  5. context 'when user has admin.core_workflow permissions' do
  6. let(:core_workflow_role) { create(:role, :admin_core_workflow) }
  7. let(:user) { create(:user, role_ids: [core_workflow_role.id]) }
  8. it 'does provide assets for application selector ui element' do
  9. expect(described_class.json_hash(user)[:collections][ObjectManager::Attribute.to_app_model]).to be_truthy
  10. end
  11. end
  12. context 'when user has ticket.agent permissions' do
  13. let(:user) { create(:agent) }
  14. it 'does provide assets for application selector ui element' do
  15. expect(described_class.json_hash(user)[:collections][ObjectManager::Attribute.to_app_model]).to be_falsey
  16. end
  17. end
  18. context 'when user has customer permissions' do
  19. let(:user) { create(:customer) }
  20. it 'does provide assets for application selector ui element' do
  21. expect(described_class.json_hash(user)[:collections][ObjectManager::Attribute.to_app_model]).to be_falsey
  22. end
  23. end
  24. end
  25. describe 'taskbars' do
  26. let(:user) { create(:user) }
  27. let(:taskbar_1) { create(:taskbar, user: user) }
  28. let(:taskbar_2) { create(:taskbar, user: user, app: 'mobile') }
  29. before { taskbar_1 && taskbar_2 }
  30. it 'returns desktop taskbars' do
  31. collections = described_class.json_hash(user)[:collections]
  32. expect(collections[Taskbar.to_app_model]).to eq([taskbar_1])
  33. end
  34. end
  35. describe 'New collections by installed packages are crashing zammad#4748' do
  36. it 'does add a collection as a file' do
  37. allow(Rails).to receive(:env).and_return('production')
  38. Rails.root.join('lib/session_helper/collection_xxx.rb').write('module SessionHelper::CollectionXXX; end;')
  39. expect { described_class.default_collections(User.find(1)) }.not_to raise_error(NameError, 'uninitialized constant SessionHelper::CollectionXxx')
  40. ensure
  41. Rails.root.join('lib/session_helper/collection_xxx.rb').delete
  42. end
  43. end
  44. end