Add error check if Exchange config gives empty folder list (fixes #1802)
This commit is contained in:
parent
a6d554cfb3
commit
97f55bcd83
3 changed files with 41 additions and 13 deletions
|
@ -25,9 +25,10 @@ class Integration::ExchangeController < ApplicationController
|
|||
def folders
|
||||
answer_with do
|
||||
Sequencer.process('Import::Exchange::AvailableFolders',
|
||||
parameters: {
|
||||
ews_config: ews_config
|
||||
})
|
||||
parameters: { ews_config: ews_config })
|
||||
.tap do |res|
|
||||
raise 'No folders found for given user credentials.' if res[:folders].blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,14 +36,12 @@ class Integration::ExchangeController < ApplicationController
|
|||
answer_with do
|
||||
raise 'Please select at least one folder.' if params[:folders].blank?
|
||||
|
||||
examples = Sequencer.process('Import::Exchange::AttributesExamples',
|
||||
parameters: {
|
||||
ews_folder_ids: params[:folders],
|
||||
ews_config: ews_config
|
||||
})
|
||||
examples.tap do |result|
|
||||
raise 'No entries found in selected folder(s).' if result[:attributes].blank?
|
||||
end
|
||||
Sequencer.process('Import::Exchange::AttributesExamples',
|
||||
parameters: { ews_folder_ids: params[:folders],
|
||||
ews_config: ews_config })
|
||||
.tap do |res|
|
||||
raise 'No entries found in selected folder(s).' if res[:attributes].blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
28
spec/requests/integration/exchange_spec.rb
Normal file
28
spec/requests/integration/exchange_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Exchange integration endpoint', type: :request do
|
||||
before { authenticated_as(admin_with_admin_user_permissions) }
|
||||
|
||||
let(:admin_with_admin_user_permissions) do
|
||||
create(:user, roles: [role_with_admin_user_permissions])
|
||||
end
|
||||
|
||||
let(:role_with_admin_user_permissions) do
|
||||
create(:role).tap { |role| role.permission_grant('admin.integration') }
|
||||
end
|
||||
|
||||
describe 'EWS folder retrieval' do
|
||||
context 'when no folders found' do
|
||||
let(:empty_folder_list) { { folders: {} } }
|
||||
|
||||
it 'responds with an error message' do
|
||||
allow(Sequencer).to receive(:process).with(any_args).and_return(empty_folder_list)
|
||||
|
||||
post api_v1_integration_exchange_folders_path,
|
||||
params: {}, as: :json
|
||||
|
||||
expect(json_response).to include('result' => 'failed').and include('message')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,8 +8,9 @@ module ZammadSpecSupportRequest
|
|||
%i[get post patch put delete head].each do |method_id|
|
||||
|
||||
define_method(method_id) do |path, **args|
|
||||
headers = Hash(headers).merge(Hash(@headers))
|
||||
super(path, headers: headers, **args)
|
||||
args = args.with_indifferent_access
|
||||
args[:headers] = Hash(args[:headers]).merge!(Hash(@headers))
|
||||
super(path, **args.symbolize_keys)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue