Add option for body to be searchable for new triggers (fixes #1989)

add tests for new body field in trigger condition
This commit is contained in:
Muhammad Nuzaihan 2018-05-15 00:01:15 +08:00 committed by Ryan Lue
parent 3800db6386
commit 903777588a
3 changed files with 117 additions and 2 deletions

View file

@ -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' } },

View file

@ -666,4 +666,49 @@ test('form checks', function() {
}
deepEqual(params, test_params, 'form param check')
});
$('#forms').append('<hr><h1>form 5</h1><form id="form5"></form>')
var el = $('#form5')
var defaults = {
condition: {
'article.body': {
operator: 'contains',
value: 'some body',
},
},
executions: {
'notification.email': {
recipient: 'ticket_customer',
subject: 'some subject',
body: "some<br>\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<br>\nbody",
},
},
}
deepEqual(params, test_params, 'form article body param check')
});

View file

@ -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 <b>title</b>\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 <b>note</b>\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 <b>title</b> äöüß', 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 <b>title</b> äöüß', 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 <b>note</b>\nnew line", article1.body)
assert_equal('text/plain', article1.content_type)
end
end