From 903777588ae9416d23a689d78c9d297e3126c813 Mon Sep 17 00:00:00 2001 From: Muhammad Nuzaihan Date: Tue, 15 May 2018 00:01:15 +0800 Subject: [PATCH] Add option for body to be searchable for new triggers (fixes #1989) add tests for new body field in trigger condition --- .../app/models/ticket_article.coffee | 2 +- public/assets/tests/form_extended.js | 47 ++++++++++++- test/unit/ticket_trigger_test.rb | 70 +++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/models/ticket_article.coffee b/app/assets/javascripts/app/models/ticket_article.coffee index 03ab869b5..99a89a957 100644 --- a/app/assets/javascripts/app/models/ticket_article.coffee +++ b/app/assets/javascripts/app/models/ticket_article.coffee @@ -8,7 +8,7 @@ class App.TicketArticle extends App.Model { name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true }, { name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true }, { name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true }, - { name: 'body', display: 'Text', tag: 'textarea', rows: 5, limit: 100, null: false, searchable: false }, + { name: 'body', display: 'Text', tag: 'textarea', rows: 5, limit: 100, null: false, searchable: true }, { name: 'type_id', display: 'Type', tag: 'select', multiple: false, null: false, relation: 'TicketArticleType', default: '' }, { name: 'sender_id', display: 'Sender', tag: 'select', multiple: false, null: false, relation: 'TicketArticleSender', default: '' }, { name: 'internal', display: 'Visibility', tag: 'radio', default: false, null: true, options: { true: 'internal', false: 'public' } }, diff --git a/public/assets/tests/form_extended.js b/public/assets/tests/form_extended.js index fa69b82e5..42f84247a 100644 --- a/public/assets/tests/form_extended.js +++ b/public/assets/tests/form_extended.js @@ -666,4 +666,49 @@ test('form checks', function() { } deepEqual(params, test_params, 'form param check') -}); \ No newline at end of file + $('#forms').append('

form 5

') + var el = $('#form5') + var defaults = { + condition: { + 'article.body': { + operator: 'contains', + value: 'some body', + }, + }, + executions: { + 'notification.email': { + recipient: 'ticket_customer', + subject: 'some subject', + body: "some
\nbody", + }, + }, + } + new App.ControllerForm({ + el: el, + model: { + configure_attributes: [ + { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true }, + { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true }, + ] + }, + params: defaults, + autofocus: true + }) + var params = App.ControllerForm.params(el) + var test_params = { + condition: { + 'article.body': { + operator: 'contains', + value: 'some body', + }, + }, + executions: { + 'notification.email': { + recipient: 'ticket_customer', + subject: 'some subject', + body: "some
\nbody", + }, + }, + } + deepEqual(params, test_params, 'form article body param check') +}); diff --git a/test/unit/ticket_trigger_test.rb b/test/unit/ticket_trigger_test.rb index 088d38ac9..c8563448f 100644 --- a/test/unit/ticket_trigger_test.rb +++ b/test/unit/ticket_trigger_test.rb @@ -4366,4 +4366,74 @@ class TicketTriggerTest < ActiveSupport::TestCase assert_equal('Lorem ipsum dolor', autoreply.body) assert_equal('text/html', autoreply.content_type) end + + test 'trigger when there is an article body contains matched values' do + trigger1 = Trigger.create_or_update( + name: 'detect message body', + condition: { + 'article.body' => { + 'operator' => 'contains', + 'value' => 'some message', + }, + }, + perform: { + 'ticket.tags' => { + 'operator' => 'add', + 'value' => 'tag1, tag2', + }, + 'notification.email' => { + 'body' => 'some lala', + 'recipient' => 'ticket_customer', + 'subject' => 'Thanks for your inquiry - loop check (#{ticket.title})!', + }, + }, + disable_notification: true, + active: true, + created_by_id: 1, + updated_by_id: 1, + ) + ticket1 = Ticket.create!( + title: "some title\n äöüß", + group: Group.lookup(name: 'Users'), + customer: User.lookup(email: 'nicole.braun@zammad.org'), + updated_by_id: 1, + created_by_id: 1, + ) + article1 = Ticket::Article.create!( + ticket_id: ticket1.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: "some message note\nnew line", + internal: false, + sender: Ticket::Article::Sender.find_by(name: 'Agent'), + type: Ticket::Article::Type.find_by(name: 'note'), + updated_by_id: 1, + created_by_id: 1, + ) + ticket1.reload + assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify') + assert_equal('Users', ticket1.group.name, 'ticket1.group verify') + assert_equal('new', ticket1.state.name, 'ticket1.state verify') + assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify') + assert_equal(1, ticket1.articles.count, 'ticket1.articles verify') + assert_equal([], ticket1.tag_list) + + Observer::Transaction.commit + + ticket1.reload + assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify') + assert_equal('Users', ticket1.group.name, 'ticket1.group verify') + assert_equal('new', ticket1.state.name, 'ticket1.state verify') + assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify') + assert_equal(2, ticket1.articles.count, 'ticket1.articles verify') + assert_equal(%w[tag1 tag2], ticket1.tag_list) + + assert_match('- ', article1.from) + assert_match('some_recipient@example.com', article1.to) + assert_match('some subject', article1.subject) + assert_match("some message note\nnew line", article1.body) + assert_equal('text/plain', article1.content_type) + end end