diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 049f676cd..e69a292c7 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1156,6 +1156,7 @@ perform changes on ticket type: Ticket::Article::Type.find_by(name: 'note'), preferences: { perform_origin: perform_origin, + notification: true, }, updated_by_id: 1, created_by_id: 1, diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb index 5d9b9b1e9..97c429388 100644 --- a/spec/models/job_spec.rb +++ b/spec/models/job_spec.rb @@ -532,4 +532,55 @@ RSpec.describe Job, type: :model do expect(ticket.reload.title).not_to eq changed_title end end + + describe 'Scheduler ignores "disable notifications == no" #3684', sends_notification_emails: true do + let!(:group) { create(:group) } + let!(:agent) { create(:agent, groups: [group]) } + let!(:ticket) { create(:ticket, group: group, owner: agent) } + let(:perform) do + { 'article.note' => { 'body' => 'ccc', 'internal' => 'true', 'subject' => 'ccc' }, 'ticket.state_id' => { 'value' => 4 } } + end + + context 'with disable_notification true' do + let!(:notify_job) { create(:job, :always_on) } + + it 'does modify the ticket' do + expect { notify_job.run(true) }.to change { ticket.reload.state } + end + + it 'does not send a notification to the owner of the ticket' do # rubocop:disable RSpec/ExampleLength + check_notification do + notify_job.run(true) + Scheduler.worker(true) + + not_sent( + template: 'ticket_update', + user: agent, + objects: hash_including({ article: nil }) + ) + end + end + end + + context 'with disable_notification false' do + let!(:notify_job) { create(:job, :always_on, disable_notification: false, perform: perform) } + + it 'does modify the ticket' do + expect { notify_job.run(true) }.to change { ticket.reload.state } + end + + it 'does send a notification to the owner of the ticket with trigger note in notification body' do # rubocop:disable RSpec/ExampleLength + check_notification do + notify_job.run(true) + Scheduler.worker(true) + + sent( + template: 'ticket_update', + user: agent, + objects: hash_including({ article: ticket.reload.articles.first }) + ) + end + end + end + end end