issue_2541_fix_notification_email_without_body_spec.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
  4. describe '"body" attribute management' do
  5. # We use #update_columns to bypass callbacks
  6. # that would prevent the record from being saved with an empty body
  7. before { subject.update_columns(perform: perform) } # rubocop:disable RSpec/NamedSubject
  8. let(:perform) do
  9. {
  10. type => {
  11. 'body' => '',
  12. 'recipient' => 'article_last_sender',
  13. 'subject' => 'Thanks for your inquiry (#{ticket.title})', # rubocop:disable Lint/InterpolationCheck
  14. },
  15. }
  16. end
  17. context 'when migrating Triggers' do
  18. subject(:trigger) { create(:trigger) }
  19. context 'for email' do
  20. let(:type) { 'notification.email' }
  21. it "updates empty perform['notification.email']['body'] attribute" do
  22. expect { migrate }.to change { trigger.reload.perform['notification.email']['body'] }.from('').to('-')
  23. end
  24. end
  25. context 'for SMS' do
  26. let(:type) { 'notification.sms' }
  27. it "updates empty perform['notification.sms']['body'] attribute" do
  28. expect { migrate }.to change { trigger.reload.perform['notification.sms']['body'] }.from('').to('-')
  29. end
  30. end
  31. end
  32. context 'when migrating Jobs' do
  33. subject(:job) { create(:job) }
  34. let(:type) { 'notification.email' }
  35. it "updates empty perform['notification.email']['body'] attribute" do
  36. expect { migrate }.to change { job.reload.perform['notification.email']['body'] }.from('').to('-')
  37. end
  38. context 'when selector contains current_user.id' do
  39. subject(:job) do
  40. UserInfo.ensure_current_user_id do
  41. create(:job, condition: { 'ticket.owner_id' => { 'operator' => 'is', 'pre_condition' => 'current_user.id', 'value' => '', 'value_completion' => '' } })
  42. end
  43. end
  44. let(:type) { 'notification.email' }
  45. it "updates empty perform['notification.email']['body'] attribute" do
  46. expect { migrate }.to change { job.reload.perform['notification.email']['body'] }.from('').to('-')
  47. end
  48. end
  49. end
  50. end
  51. describe 'scheduler management' do
  52. let(:scheduler) { Scheduler.find_by(method: 'Job.run') }
  53. before { scheduler.update!(active: false) }
  54. it "re-enables 'Job.run' Scheduler" do
  55. expect { migrate }.to change { scheduler.reload.active }.to(true)
  56. end
  57. end
  58. end