Browse Source

Fixes #3684 - Scheduler ignores "disable notifications == no".

Rolf Schmidt 3 years ago
parent
commit
2f72ac96d0
2 changed files with 52 additions and 0 deletions
  1. 1 0
      app/models/ticket.rb
  2. 51 0
      spec/models/job_spec.rb

+ 1 - 0
app/models/ticket.rb

@@ -1156,6 +1156,7 @@ perform changes on ticket
       type:          Ticket::Article::Type.find_by(name: 'note'),
       type:          Ticket::Article::Type.find_by(name: 'note'),
       preferences:   {
       preferences:   {
         perform_origin: perform_origin,
         perform_origin: perform_origin,
+        notification:   true,
       },
       },
       updated_by_id: 1,
       updated_by_id: 1,
       created_by_id: 1,
       created_by_id: 1,

+ 51 - 0
spec/models/job_spec.rb

@@ -532,4 +532,55 @@ RSpec.describe Job, type: :model do
       expect(ticket.reload.title).not_to eq changed_title
       expect(ticket.reload.title).not_to eq changed_title
     end
     end
   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
 end