Fixes #3741 - Removal of Microsoft365-Channel not possible via UI when having no email address relation.
This commit is contained in:
parent
f8240e85e0
commit
2d31b6ced4
2 changed files with 51 additions and 1 deletions
|
@ -55,7 +55,7 @@ class ChannelsMicrosoft365Controller < ApplicationController
|
|||
def destroy
|
||||
channel = Channel.find_by(id: params[:id], area: 'Microsoft365::Account')
|
||||
email = EmailAddress.find_by(channel_id: channel.id)
|
||||
email.destroy!
|
||||
email&.destroy!
|
||||
channel.destroy!
|
||||
render json: {}
|
||||
end
|
||||
|
|
50
spec/requests/channels_microsoft365_spec.rb
Normal file
50
spec/requests/channels_microsoft365_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Microsoft365 channel API endpoints', type: :request do
|
||||
let(:admin) { create(:admin) }
|
||||
let!(:microsoft365_channel) { create(:microsoft365_channel) }
|
||||
|
||||
describe 'DELETE /api/v1/channels_microsoft365', authenticated_as: :admin do
|
||||
context 'without a email address relation' do
|
||||
let(:params) do
|
||||
{
|
||||
id: microsoft365_channel.id
|
||||
}
|
||||
end
|
||||
|
||||
it 'responds 200 OK' do
|
||||
delete '/api/v1/channels_microsoft365', params: params, as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it 'microsoft365 channel deleted' do
|
||||
expect { delete '/api/v1/channels_microsoft365', params: params, as: :json }.to change(Channel, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a email address relation' do
|
||||
let(:params) do
|
||||
{
|
||||
id: microsoft365_channel.id
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
create(:email_address, channel: microsoft365_channel)
|
||||
end
|
||||
|
||||
it 'responds 200 OK' do
|
||||
delete '/api/v1/channels_microsoft365', params: params, as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it 'microsoft365 channel and related email address deleted' do
|
||||
expect { delete '/api/v1/channels_microsoft365', params: params, as: :json }.to change(Channel, :count).by(-1).and change(EmailAddress, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue