exchange_spec.rb 1.7 KB

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