exchange_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'rails_helper'
  2. RSpec.describe 'Exchange integration endpoint', type: :request do
  3. before { authenticated_as(admin_with_admin_user_permissions) }
  4. let(:admin_with_admin_user_permissions) do
  5. create(:user, roles: [role_with_admin_user_permissions])
  6. end
  7. let(:role_with_admin_user_permissions) do
  8. create(:role).tap { |role| role.permission_grant('admin.integration') }
  9. end
  10. describe 'EWS folder retrieval' do
  11. # see https://github.com/zammad/zammad/issues/1802
  12. context 'when no folders found (#1802)' do
  13. let(:empty_folder_list) { { folders: {} } }
  14. it 'responds with an error message' do
  15. allow(Sequencer).to receive(:process).with(any_args).and_return(empty_folder_list)
  16. post api_v1_integration_exchange_folders_path,
  17. params: {}, as: :json
  18. expect(json_response).to include('result' => 'failed').and include('message')
  19. end
  20. end
  21. end
  22. describe 'autodiscovery' do
  23. # see https://github.com/zammad/zammad/issues/2065
  24. context 'when Autodiscover gem raises Errno::EADDRNOTAVAIL (#2065)' do
  25. let(:client) { instance_double('Autodiscover::Client') }
  26. it 'rescues and responds with an empty hash (to proceed to manual configuration)' do
  27. allow(Autodiscover::Client).to receive(:new).with(any_args).and_return(client)
  28. allow(client).to receive(:autodiscover).and_raise(Errno::EADDRNOTAVAIL)
  29. post api_v1_integration_exchange_autodiscover_path,
  30. params: {}, as: :json
  31. expect(json_response).to eq('result' => 'ok')
  32. end
  33. end
  34. end
  35. end