set_email_notification_configuration_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::System::SetEmailNotificationConfiguration do
  4. let(:service) { described_class.new(adapter:, new_configuration:) }
  5. context 'when adapter is sendmail' do
  6. let(:adapter) { 'sendmail' }
  7. let(:new_configuration) { nil }
  8. before do
  9. channel_by_adapter('sendmail').update!(active: false)
  10. channel_by_adapter('smtp').update!(active: true)
  11. service.execute
  12. end
  13. it 'sets smtp to inactive' do
  14. expect(channel_by_adapter('smtp'))
  15. .to have_attributes(
  16. active: false
  17. )
  18. end
  19. it 'sets sendmail to active' do
  20. expect(channel_by_adapter('sendmail'))
  21. .to have_attributes(
  22. active: true,
  23. status_out: 'ok',
  24. last_log_out: nil
  25. )
  26. end
  27. end
  28. context 'when adapter is smtp' do
  29. before { service.execute }
  30. let(:adapter) { 'smtp' }
  31. let(:new_configuration) do
  32. {
  33. adapter: 'smtp',
  34. host: 'smtp.example.com',
  35. port: 25,
  36. ssl: true,
  37. user: 'some@example.com',
  38. password: 'password',
  39. ssl_verify: false,
  40. }
  41. end
  42. it 'sets smtp to active and updates configuration' do
  43. expect(channel_by_adapter('smtp'))
  44. .to have_attributes(
  45. active: true,
  46. status_out: 'ok',
  47. last_log_out: nil,
  48. options: include(
  49. outbound: include(
  50. adapter: 'smtp',
  51. options: include(
  52. host: 'smtp.example.com',
  53. port: 25,
  54. ssl: true,
  55. user: 'some@example.com',
  56. password: 'password',
  57. ssl_verify: false,
  58. )
  59. )
  60. )
  61. )
  62. end
  63. it 'sets sendmail to inactive' do
  64. expect(channel_by_adapter('sendmail'))
  65. .to have_attributes(
  66. active: false
  67. )
  68. end
  69. end
  70. def channel_by_adapter(adapter)
  71. Channel
  72. .where(area: 'Email::Notification')
  73. .to_a
  74. .find { _1.options.dig(:outbound, :adapter) == adapter }
  75. end
  76. end