123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- # rubocop:disable Lint/InterpolationCheck
- require 'test_helper'
- class EmailProcessBounceFollowUpTest < ActiveSupport::TestCase
- test 'process with bounce follow up check' do
- ticket = Ticket.create(
- title: 'bounce check',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'bounce check',
- message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
- body: 'some message bounce check',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- )
- travel 1.second
- email_raw_string = IO.binread('test/fixtures/mail33-undelivered-mail-returned-to-sender.box')
- ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('new', ticket_p.state.name)
- travel_back
- ticket.destroy
- end
- test 'process with bounce trigger email loop check - article based blocker' do
- roles = Role.where(name: %w[Customer])
- customer1 = User.create_or_update(
- login: 'ticket-bounce-trigger1@example.com',
- firstname: 'Notification',
- lastname: 'Customer1',
- email: 'ticket-bounce-trigger1@example.com',
- active: true,
- roles: roles,
- preferences: {},
- updated_by_id: 1,
- created_by_id: 1,
- )
- Trigger.create_or_update(
- name: 'auto reply new ticket',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'create',
- },
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- Trigger.create_or_update(
- name: 'auto reply followup',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'update',
- },
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your follow up (#{ticket.title})!',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- ticket = Ticket.create(
- title: 'bounce check',
- group: Group.lookup(name: 'Users'),
- customer: customer1,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'bounce check',
- message_id: '<20150830145601.30.6088xx@edenhofer.zammad.com>',
- body: 'some message bounce check',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Observer::Transaction.commit
- assert_equal('new', ticket.state.name)
- assert_equal(2, ticket.articles.count)
- article = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: customer1.email,
- subject: 'bounce check 2',
- message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
- body: 'some message bounce check 2',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Observer::Transaction.commit
- assert_equal(4, ticket.articles.count)
- travel 1.second
- email_raw_string = IO.binread('test/fixtures/mail33-undelivered-mail-returned-to-sender.box')
- ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('open', ticket_p.state.name)
- assert_equal(5, ticket_p.articles.count)
- travel_back
- ticket.destroy
- end
- test 'process with bounce trigger email loop check - bounce based blocker' do
- roles = Role.where(name: %w[Customer])
- customer2 = User.create_or_update(
- login: 'ticket-bounce-trigger2@example.com',
- firstname: 'Notification',
- lastname: 'Customer2',
- email: 'ticket-bounce-trigger2@example.com',
- active: true,
- roles: roles,
- preferences: {},
- updated_by_id: 1,
- created_by_id: 1,
- )
- Trigger.create_or_update(
- name: 'auto reply new ticket',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'create',
- },
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- Trigger.create_or_update(
- name: 'auto reply followup',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'update',
- },
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your follow up (#{ticket.title})!',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- ticket = Ticket.create(
- title: 'bounce check',
- group: Group.lookup(name: 'Users'),
- customer: customer2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'bounce check',
- message_id: '<20150830145601.30.6088xx@edenhofer.zammad.com>',
- body: 'some message bounce check',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Observer::Transaction.commit
- assert_equal('new', ticket.state.name)
- assert_equal(2, ticket.articles.count)
- article = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'bounce check 2',
- message_id: '<20170526150141.232.13312@example.zammad.loc>',
- body: 'some message bounce check 2',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Observer::Transaction.commit
- assert_equal(4, ticket.articles.count)
- travel 1.second
- email_raw_string = IO.binread('test/fixtures/mail55.box')
- ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('open', ticket_p.state.name)
- assert_equal(5, ticket_p.articles.count)
- travel_back
- ticket.destroy
- end
- end
|