channels_microsoft365_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Microsoft365 channel API endpoints', type: :request do
  4. let(:admin) { create(:admin) }
  5. let!(:microsoft365_channel) { create(:microsoft365_channel) }
  6. describe 'DELETE /api/v1/channels_microsoft365', authenticated_as: :admin do
  7. context 'without a email address relation' do
  8. let(:params) do
  9. {
  10. id: microsoft365_channel.id
  11. }
  12. end
  13. it 'responds 200 OK' do
  14. delete '/api/v1/channels_microsoft365', params: params, as: :json
  15. expect(response).to have_http_status(:ok)
  16. end
  17. it 'microsoft365 channel deleted' do
  18. expect { delete '/api/v1/channels_microsoft365', params: params, as: :json }.to change(Channel, :count).by(-1)
  19. end
  20. end
  21. context 'with a email address relation' do
  22. let(:params) do
  23. {
  24. id: microsoft365_channel.id
  25. }
  26. end
  27. before do
  28. create(:email_address, channel: microsoft365_channel)
  29. end
  30. it 'responds 200 OK' do
  31. delete '/api/v1/channels_microsoft365', params: params, as: :json
  32. expect(response).to have_http_status(:ok)
  33. end
  34. it 'microsoft365 channel and related email address deleted' do
  35. expect { delete '/api/v1/channels_microsoft365', params: params, as: :json }.to change(Channel, :count).by(-1).and change(EmailAddress, :count).by(-1)
  36. end
  37. end
  38. end
  39. end