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
|
def folders
|
||||||
answer_with do
|
answer_with do
|
||||||
Sequencer.process('Import::Exchange::AvailableFolders',
|
Sequencer.process('Import::Exchange::AvailableFolders',
|
||||||
parameters: {
|
parameters: { ews_config: ews_config })
|
||||||
ews_config: ews_config
|
.tap do |res|
|
||||||
})
|
raise 'No folders found for given user credentials.' if res[:folders].blank?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,14 +36,12 @@ class Integration::ExchangeController < ApplicationController
|
||||||
answer_with do
|
answer_with do
|
||||||
raise 'Please select at least one folder.' if params[:folders].blank?
|
raise 'Please select at least one folder.' if params[:folders].blank?
|
||||||
|
|
||||||
examples = Sequencer.process('Import::Exchange::AttributesExamples',
|
Sequencer.process('Import::Exchange::AttributesExamples',
|
||||||
parameters: {
|
parameters: { ews_folder_ids: params[:folders],
|
||||||
ews_folder_ids: params[:folders],
|
ews_config: ews_config })
|
||||||
ews_config: ews_config
|
.tap do |res|
|
||||||
})
|
raise 'No entries found in selected folder(s).' if res[:attributes].blank?
|
||||||
examples.tap do |result|
|
end
|
||||||
raise 'No entries found in selected folder(s).' if result[:attributes].blank?
|
|
||||||
end
|
|
||||||
end
|
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|
|
%i[get post patch put delete head].each do |method_id|
|
||||||
|
|
||||||
define_method(method_id) do |path, **args|
|
define_method(method_id) do |path, **args|
|
||||||
headers = Hash(headers).merge(Hash(@headers))
|
args = args.with_indifferent_access
|
||||||
super(path, headers: headers, **args)
|
args[:headers] = Hash(args[:headers]).merge!(Hash(@headers))
|
||||||
|
super(path, **args.symbolize_keys)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue