channels_google_spec.rb 1.4 KB

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