Improved reply to / recipient tests.

This commit is contained in:
Martin Edenhofer 2017-10-09 01:37:08 +02:00
parent 6afd9f99b5
commit 6e227f5b71
2 changed files with 60 additions and 15 deletions

View file

@ -938,10 +938,19 @@ class App.Utils
return articleNew return articleNew
if type.name is 'email' || type.name is 'web' if type.name is 'email' || type.name is 'web'
localEmailAddresses = []
for address in email_addresses
if address && !_.isEmpty(address.email)
localEmailAddresses.push address.email.toString().toLowerCase()
isLocalAddress = (address) ->
return false if _.isEmpty(address)
_.contains(localEmailAddresses, address.toString().toLowerCase())
article_created_by_email = undefined article_created_by_email = undefined
if article_created_by && article_created_by.email if article_created_by && article_created_by.email
article_created_by_email = article_created_by.email.toLowerCase() article_created_by_email = article_created_by.email.toLowerCase()
if article.sender.name is 'Agent' && article_created_by_email && article.from && !article.from.match(article_created_by_email) if article.sender.name is 'Agent' && ((article_created_by_email && article.from && !article.from.match(article_created_by_email)) || isLocalAddress(article.from))
articleNew.to = article.to articleNew.to = article.to
else else
if article.reply_to if article.reply_to
@ -957,15 +966,6 @@ class App.Utils
# filter for uniq recipients # filter for uniq recipients
recipientAddresses = {} recipientAddresses = {}
localEmailAddresses = []
for address in email_addresses
if address && !_.isEmpty(address.email)
localEmailAddresses.push address.email.toString().toLowerCase()
isLocalAddress = (address) ->
return false if _.isEmpty(address)
_.contains(localEmailAddresses, address.toString().toLowerCase())
addAddresses = (addressLine, line) -> addAddresses = (addressLine, line) ->
lineNew = '' lineNew = ''
recipients = emailAddresses.parseAddressList(addressLine) recipients = emailAddresses.parseAddressList(addressLine)

View file

@ -2321,7 +2321,7 @@ test('check getRecipientArticle format', function() {
customer: customer, customer: customer,
} }
article = { article = {
message_id: 'message_id15', message_id: 'message_id16',
created_by: customer, created_by: customer,
type: { type: {
name: 'email', name: 'email',
@ -2337,7 +2337,7 @@ test('check getRecipientArticle format', function() {
to: 'customer@example.com, customer1@example.com, customer2@example.com, customer2+2@example.com', to: 'customer@example.com, customer1@example.com, customer2@example.com, customer2+2@example.com',
cc: '', cc: '',
body: '', body: '',
in_reply_to: 'message_id15', in_reply_to: 'message_id16',
} }
email_addresses = [ email_addresses = [
{ {
@ -2360,13 +2360,13 @@ test('check getRecipientArticle format', function() {
login: 'login', login: 'login',
firstname: 'firstname', firstname: 'firstname',
lastname: 'lastname', lastname: 'lastname',
email: 'agent@example.com', email: 'zammad@example.com',
} }
ticket = { ticket = {
customer: customer, customer: customer,
} }
article = { article = {
message_id: 'message_id16', message_id: 'message_id17',
created_by: agent, created_by: agent,
type: { type: {
name: 'email', name: 'email',
@ -2382,7 +2382,7 @@ test('check getRecipientArticle format', function() {
to: 'customer@example.com', to: 'customer@example.com',
cc: '', cc: '',
body: '', body: '',
in_reply_to: 'message_id16', in_reply_to: 'message_id17',
} }
email_addresses = [ email_addresses = [
{ {
@ -2395,6 +2395,51 @@ test('check getRecipientArticle format', function() {
verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true)
deepEqual(verify, result) deepEqual(verify, result)
customer = {
login: 'login',
firstname: 'firstname',
lastname: 'lastname',
email: 'customer@example.com',
}
agent = {
login: 'login',
firstname: 'firstname',
lastname: 'lastname',
email: 'zammad@example.com',
}
ticket = {
customer: customer,
}
article = {
message_id: 'message_id18',
created_by: agent,
type: {
name: 'email',
},
sender: {
name: 'Agent',
},
from: 'zammad@example.com',
to: 'customer@example.com',
cc: '',
}
result = {
to: 'customer@example.com',
cc: '',
body: '',
in_reply_to: 'message_id18',
}
email_addresses = [
{
email: 'zammad@example.com',
},
{
email: 'zammad2@example.com',
}
]
verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false)
deepEqual(verify, result)
}); });
} }