123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311 |
- require 'test_helper'
- class TicketNotificationTest < ActiveSupport::TestCase
- setup do
- Setting.set('timezone_default', 'Europe/Berlin')
- Trigger.create_or_update(
- name: 'auto reply - new ticket',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'create',
- },
- 'ticket.state_id' => {
- 'operator' => 'is not',
- 'value' => Ticket::State.lookup(name: 'closed').id,
- },
- 'article.type_id' => {
- 'operator' => 'is',
- 'value' => [
- Ticket::Article::Type.lookup(name: 'email').id,
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'web').id,
- ],
- },
- },
- perform: {
- 'notification.email' => {
- # rubocop:disable Lint/InterpolationCheck
- 'body' => '<p>Your request (Ticket##{ticket.number}) has been received and will be reviewed by our support staff.<p>
- <br/>
- <p>To provide additional information, please reply to this email or click on the following link:
- <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
- </p>
- <br/>
- <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your inquiry (#{ticket.title})',
- # rubocop:enable Lint/InterpolationCheck
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- # create @agent1 & @agent2
- Group.create_or_update(
- name: 'TicketNotificationTest',
- updated_by_id: 1,
- created_by_id: 1
- )
- groups = Group.where(name: 'TicketNotificationTest')
- roles = Role.where(name: 'Agent')
- @agent1 = User.create_or_update(
- login: 'ticket-notification-agent1@example.com',
- firstname: 'Notification',
- lastname: 'Agent1',
- email: 'ticket-notification-agent1@example.com',
- password: 'agentpw',
- out_of_office: false,
- active: true,
- roles: roles,
- groups: groups,
- preferences: {
- locale: 'de-de',
- },
- updated_by_id: 1,
- created_by_id: 1,
- )
- @agent2 = User.create_or_update(
- login: 'ticket-notification-agent2@example.com',
- firstname: 'Notification',
- lastname: 'Agent2',
- email: 'ticket-notification-agent2@example.com',
- password: 'agentpw',
- out_of_office: false,
- active: true,
- roles: roles,
- groups: groups,
- preferences: {
- locale: 'en-us',
- timezone: 'America/St_Lucia',
- },
- updated_by_id: 1,
- created_by_id: 1,
- )
- @agent3 = User.create_or_update(
- login: 'ticket-notification-agent3@example.com',
- firstname: 'Notification',
- lastname: 'Agent3',
- email: 'ticket-notification-agent3@example.com',
- password: 'agentpw',
- out_of_office: false,
- active: true,
- roles: roles,
- groups: groups,
- preferences: {
- locale: 'de-de',
- },
- updated_by_id: 1,
- created_by_id: 1,
- )
- @agent4 = User.create_or_update(
- login: 'ticket-notification-agent4@example.com',
- firstname: 'Notification',
- lastname: 'Agent4',
- email: 'ticket-notification-agent4@example.com',
- password: 'agentpw',
- out_of_office: false,
- active: true,
- roles: roles,
- groups: groups,
- preferences: {
- locale: 'de-de',
- },
- updated_by_id: 1,
- created_by_id: 1,
- )
- Group.create_if_not_exists(
- name: 'WithoutAccess',
- note: 'Test for notification check.',
- updated_by_id: 1,
- created_by_id: 1
- )
- # create @customer
- roles = Role.where(name: 'Customer')
- @customer = User.create_or_update(
- login: 'ticket-notification-customer@example.com',
- firstname: 'Notification',
- lastname: 'Customer',
- email: 'ticket-notification-customer@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: groups,
- updated_by_id: 1,
- created_by_id: 1,
- )
- end
- test 'ticket notification - to all agents / to explicit agents' do
- # create ticket in group
- ApplicationHandleInfo.current = 'scheduler.postmaster'
- ticket1 = Ticket.create!(
- title: 'some notification test 1',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- 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',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- assert(ticket1)
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- # create ticket in group
- ApplicationHandleInfo.current = 'application_server'
- ticket1 = Ticket.create!(
- title: 'some notification test 2',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- 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',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- assert(ticket1)
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- end
- test 'ticket notification - simple' do
- # create ticket in group
- ApplicationHandleInfo.current = 'application_server'
- ticket1 = Ticket.create!(
- title: 'some notification test 3',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- 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',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- assert(ticket1, 'ticket created - ticket notification simple')
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- # update ticket attributes
- ticket1.title = "#{ticket1.title} - #2"
- ticket1.priority = Ticket::Priority.lookup(name: '3 high')
- ticket1.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- # add article to ticket
- Ticket::Article.create!(
- ticket_id: ticket1.id,
- from: 'some person',
- subject: 'some note',
- body: 'some message',
- internal: true,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'note').first,
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to not to @agent1 but to @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- # update ticket by user
- ticket1.owner_id = @agent1.id
- ticket1.updated_by_id = @agent1.id
- ticket1.save!
- Ticket::Article.create!(
- ticket_id: ticket1.id,
- from: 'some person',
- subject: 'some note',
- body: 'some message',
- internal: true,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'note').first,
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to not to @agent1 but to @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- # create ticket with @agent1 as owner
- ticket2 = Ticket.create!(
- title: 'some notification test 4',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer_id: 2,
- owner_id: @agent1.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket2.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'phone').first,
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- assert(ticket2, 'ticket created')
- # verify notifications to no one
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- # update ticket
- ticket2.title = "#{ticket2.title} - #2"
- ticket2.updated_by_id = @agent1.id
- ticket2.priority = Ticket::Priority.lookup(name: '3 high')
- ticket2.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to none
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- # update ticket
- ticket2.title = "#{ticket2.title} - #3"
- ticket2.updated_by_id = @agent2.id
- ticket2.priority = Ticket::Priority.lookup(name: '2 normal')
- ticket2.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 and not to @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- # create ticket with @agent2 and @agent1 as owner
- ticket3 = Ticket.create!(
- title: 'some notification test 5',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer_id: 2,
- owner_id: @agent1.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent2.id,
- created_by_id: @agent2.id,
- )
- article_inbound = Ticket::Article.create!(
- ticket_id: ticket3.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'phone').first,
- updated_by_id: @agent2.id,
- created_by_id: @agent2.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- assert(ticket3, 'ticket created')
- # verify notifications to @agent1 and not to @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id)
- # update ticket
- ticket3.title = "#{ticket3.title} - #2"
- ticket3.updated_by_id = @agent1.id
- ticket3.priority = Ticket::Priority.lookup(name: '3 high')
- ticket3.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to no one
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id)
- # update ticket
- ticket3.title = "#{ticket3.title} - #3"
- ticket3.updated_by_id = @agent2.id
- ticket3.priority = Ticket::Priority.lookup(name: '2 normal')
- ticket3.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 and not to @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id)
- # update article / not notification should be sent
- article_inbound.internal = true
- article_inbound.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications not to @agent1 and not to @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id)
- delete = ticket1.destroy
- assert(delete, 'ticket1 destroy')
- delete = ticket2.destroy
- assert(delete, 'ticket2 destroy')
- delete = ticket3.destroy
- assert(delete, 'ticket3 destroy')
- end
- test 'ticket notification - no notification' do
- # create ticket in group
- ticket1 = Ticket.create!(
- title: 'some notification test 1 - no notification',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- 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',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- assert(ticket1, 'ticket created - ticket no notification')
- # execute object transaction
- Observer::Transaction.commit(disable_notification: true)
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- end
- test 'ticket notification - z preferences tests' do
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = false
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = false
- @agent1.save!
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent2.save!
- # create ticket in group
- ApplicationHandleInfo.current = 'scheduler.postmaster'
- ticket1 = Ticket.create!(
- title: 'some notification test - z preferences tests 1',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- 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',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- # update ticket attributes
- ticket1.title = "#{ticket1.title} - #2"
- ticket1.priority = Ticket::Priority.lookup(name: '3 high')
- ticket1.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- # create ticket in group
- ticket2 = Ticket.create!(
- title: 'some notification test - z preferences tests 2',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- owner: @agent1,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket2.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- # update ticket attributes
- ticket2.title = "#{ticket2.title} - #2"
- ticket2.priority = Ticket::Priority.lookup(name: '3 high')
- ticket2.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- # create ticket in group
- ticket3 = Ticket.create!(
- title: 'some notification test - z preferences tests 3',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- owner: @agent2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket3.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id)
- # update ticket attributes
- ticket3.title = "#{ticket3.title} - #2"
- ticket3.priority = Ticket::Priority.lookup(name: '3 high')
- ticket3.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id)
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'TicketNotificationTest').id.to_s]
- @agent1.save!
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent1.preferences['notification_config']['group_ids'] = ['-']
- @agent2.save!
- travel 1.minute # to skip loopup cache in Transaction::Notification
- # create ticket in group
- ApplicationHandleInfo.current = 'scheduler.postmaster'
- ticket4 = Ticket.create!(
- title: 'some notification test - z preferences tests 4',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket4.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, @agent1, 'email'), ticket4.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, @agent2, 'email'), ticket4.id)
- # update ticket attributes
- ticket4.title = "#{ticket4.title} - #2"
- ticket4.priority = Ticket::Priority.lookup(name: '3 high')
- ticket4.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, @agent1, 'email'), ticket4.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, @agent2, 'email'), ticket4.id)
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'TicketNotificationTest').id.to_s]
- @agent1.save!
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent2.preferences['notification_config']['group_ids'] = [99]
- @agent2.save!
- travel 1.minute # to skip loopup cache in Transaction::Notification
- # create ticket in group
- ApplicationHandleInfo.current = 'scheduler.postmaster'
- ticket5 = Ticket.create!(
- title: 'some notification test - z preferences tests 5',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket5.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket5, @agent1, 'email'), ticket5.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, @agent2, 'email'), ticket5.id)
- # update ticket attributes
- ticket5.title = "#{ticket5.title} - #2"
- ticket5.priority = Ticket::Priority.lookup(name: '3 high')
- ticket5.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket5, @agent1, 'email'), ticket5.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, @agent2, 'email'), ticket5.id)
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent1.preferences['notification_config']['group_ids'] = [999]
- @agent1.save!
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent2.preferences['notification_config']['group_ids'] = [999]
- @agent2.save!
- travel 1.minute # to skip loopup cache in Transaction::Notification
- # create ticket in group
- ApplicationHandleInfo.current = 'scheduler.postmaster'
- ticket6 = Ticket.create!(
- title: 'some notification test - z preferences tests 6',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- owner: @agent1,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket6.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'email'), ticket6.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'online'), ticket6.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'email'), ticket6.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'online'), ticket6.id)
- # update ticket attributes
- ticket6.title = "#{ticket6.title} - #2"
- ticket6.priority = Ticket::Priority.lookup(name: '3 high')
- ticket6.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'email'), ticket6.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'online'), ticket6.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'email'), ticket6.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'online'), ticket6.id)
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent1.preferences['notification_config']['matrix']['create']['channel']['email'] = false
- @agent1.preferences['notification_config']['matrix']['create']['channel']['online'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent1.preferences['notification_config']['matrix']['update']['channel']['email'] = false
- @agent1.preferences['notification_config']['matrix']['update']['channel']['online'] = true
- @agent1.preferences['notification_config']['group_ids'] = [999]
- @agent1.save!
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
- @agent2.preferences['notification_config']['matrix']['create']['channel']['email'] = false
- @agent2.preferences['notification_config']['matrix']['create']['channel']['online'] = true
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
- @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
- @agent2.preferences['notification_config']['matrix']['update']['channel']['email'] = false
- @agent2.preferences['notification_config']['matrix']['update']['channel']['online'] = true
- @agent2.preferences['notification_config']['group_ids'] = [999]
- @agent2.save!
- travel 1.minute # to skip loopup cache in Transaction::Notification
- # create ticket in group
- ApplicationHandleInfo.current = 'scheduler.postmaster'
- ticket7 = Ticket.create!(
- title: 'some notification test - z preferences tests 7',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- owner: @agent1,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket7.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'email'), ticket7.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'online'), ticket7.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'email'), ticket7.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'online'), ticket7.id)
- # update ticket attributes
- ticket7.title = "#{ticket7.title} - #2"
- ticket7.priority = Ticket::Priority.lookup(name: '3 high')
- ticket7.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'email'), ticket7.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'online'), ticket7.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'email'), ticket7.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'online'), ticket7.id)
- end
- test 'ticket notification events' do
- # create ticket in group
- ticket1 = Ticket.create!(
- title: 'some notification event test 1',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- 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',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- assert(ticket1, 'ticket created')
- # execute object transaction
- Observer::Transaction.commit
- # update ticket attributes
- ticket1.title = "#{ticket1.title} - #2"
- ticket1.priority = Ticket::Priority.lookup(name: '3 high')
- ticket1.save!
- list = EventBuffer.list('transaction')
- list_objects = Observer::Transaction.get_uniq_changes(list)
- assert_equal('some notification event test 1', list_objects['Ticket'][ticket1.id][:changes]['title'][0])
- assert_equal('some notification event test 1 - #2', list_objects['Ticket'][ticket1.id][:changes]['title'][1])
- assert_not(list_objects['Ticket'][ticket1.id][:changes]['priority'])
- assert_equal(2, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][0])
- assert_equal(3, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][1])
- # update ticket attributes
- ticket1.title = "#{ticket1.title} - #3"
- ticket1.priority = Ticket::Priority.lookup(name: '1 low')
- ticket1.save!
- list = EventBuffer.list('transaction')
- list_objects = Observer::Transaction.get_uniq_changes(list)
- assert_equal('some notification event test 1', list_objects['Ticket'][ticket1.id][:changes]['title'][0])
- assert_equal('some notification event test 1 - #2 - #3', list_objects['Ticket'][ticket1.id][:changes]['title'][1])
- assert_not(list_objects['Ticket'][ticket1.id][:changes]['priority'])
- assert_equal(2, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][0])
- assert_equal(1, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][1])
- end
- test 'ticket notification - out of office' do
- # create ticket in group
- ticket1 = Ticket.create!(
- title: 'some notification test out of office',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- owner_id: @agent2.id,
- #state: Ticket::State.lookup(name: 'new'),
- #priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- 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',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- assert(ticket1, 'ticket created - ticket notification simple')
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent3, 'email'), ticket1.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent4, 'email'), ticket1.id)
- @agent2.out_of_office = true
- @agent2.preferences[:out_of_office_text] = 'at the doctor'
- @agent2.out_of_office_replacement_id = @agent3.id
- @agent2.out_of_office_start_at = Time.zone.today - 2.days
- @agent2.out_of_office_end_at = Time.zone.today + 2.days
- @agent2.save!
- # create ticket in group
- ticket2 = Ticket.create!(
- title: 'some notification test out of office',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- owner_id: @agent2.id,
- #state: Ticket::State.lookup(name: 'new'),
- #priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- Ticket::Article.create!(
- ticket_id: ticket2.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- assert(ticket2, 'ticket created - ticket notification simple')
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent3, 'email'), ticket2.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent4, 'email'), ticket2.id)
- # update ticket attributes
- ticket2.title = "#{ticket2.title} - #2"
- ticket2.priority = Ticket::Priority.lookup(name: '3 high')
- ticket2.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, @agent3, 'email'), ticket2.id)
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent4, 'email'), ticket2.id)
- @agent3.out_of_office = true
- @agent3.preferences[:out_of_office_text] = 'at the doctor'
- @agent3.out_of_office_replacement_id = @agent4.id
- @agent3.out_of_office_start_at = Time.zone.today - 2.days
- @agent3.out_of_office_end_at = Time.zone.today + 2.days
- @agent3.save!
- # update ticket attributes
- ticket2.title = "#{ticket2.title} - #3"
- ticket2.priority = Ticket::Priority.lookup(name: '3 high')
- ticket2.save!
- # execute object transaction
- Observer::Transaction.commit
- Scheduler.worker(true)
- # verify notifications to @agent1 + @agent2
- assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id)
- assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id)
- assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket2, @agent3, 'email'), ticket2.id)
- assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent4, 'email'), ticket2.id)
- end
- test 'ticket notification template' do
- # create ticket in group
- ticket1 = Ticket.create!(
- title: 'some notification template test 1 Bobs\'s resumé',
- group: Group.lookup(name: 'TicketNotificationTest'),
- customer: @customer,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- article = 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\nnewline1 abc\nnewline2",
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- updated_by_id: @customer.id,
- created_by_id: @customer.id,
- )
- assert(ticket1, 'ticket created - ticket notification template')
- bg = Transaction::Notification.new(
- ticket_id: ticket1.id,
- article_id: article.id,
- type: 'update',
- changes: {
- 'priority_id' => [1, 2],
- 'pending_time' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
- },
- user_id: ticket1.updated_by_id,
- )
- # check changed attributes
- human_changes = bg.human_changes(@agent2, ticket1)
- assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
- assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute')
- assert_equal('1 low', human_changes['Priority'][0])
- assert_equal('2 normal', human_changes['Priority'][1])
- assert_equal('', human_changes['Pending till'][0].to_s)
- assert_equal('2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s)
- assert_not(human_changes['priority_id'])
- assert_not(human_changes['pending_time'])
- assert_not(human_changes['pending_till'])
- # en notification
- result = NotificationFactory::Mailer.template(
- locale: @agent2.preferences[:locale],
- timezone: @agent2.preferences[:timezone],
- template: 'ticket_update',
- objects: {
- ticket: ticket1,
- article: article,
- recipient: @agent2,
- changes: human_changes,
- },
- )
- assert_match(/Bobs's resumé/, result[:subject])
- assert_match(/Priority/, result[:body])
- assert_match(/1 low/, result[:body])
- assert_match(/2 normal/, result[:body])
- assert_match(/Pending till/, result[:body])
- assert_match('01/11/2015 19:33 (America/St_Lucia)', result[:body])
- assert_match(/update/, result[:body])
- assert_no_match(/pending_till/, result[:body])
- assert_no_match(/i18n/, result[:body])
- human_changes = bg.human_changes(@agent1, ticket1)
- assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
- assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute')
- assert_equal('1 niedrig', human_changes['Priority'][0])
- assert_equal('2 normal', human_changes['Priority'][1])
- assert_equal('', human_changes['Pending till'][0].to_s)
- assert_equal('2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s)
- assert_not(human_changes['priority_id'])
- assert_not(human_changes['pending_time'])
- assert_not(human_changes['pending_till'])
- # de & Europe/Berlin notification
- result = NotificationFactory::Mailer.template(
- locale: @agent1.preferences[:locale],
- timezone: @agent1.preferences[:timezone],
- template: 'ticket_update',
- objects: {
- ticket: ticket1,
- article: article,
- recipient: @agent1,
- changes: human_changes,
- },
- )
- assert_match(/Bobs's resumé/, result[:subject])
- assert_match(/Priorität/, result[:body])
- assert_match(/1 niedrig/, result[:body])
- assert_match(/2 normal/, result[:body])
- assert_match(/Warten/, result[:body])
- assert_match('12.01.2015 00:33 (Europe/Berlin)', result[:body])
- assert_match(/aktualis/, result[:body])
- assert_no_match(/pending_till/, result[:body])
- assert_no_match(/i18n/, result[:body])
- bg = Transaction::Notification.new(
- ticket_id: ticket1.id,
- article_id: article.id,
- type: 'update',
- changes: {
- title: ['some notification template test old 1', 'some notification template test 1 #2'],
- priority_id: [2, 3],
- },
- user_id: @customer.id,
- )
- # check changed attributes
- human_changes = bg.human_changes(@agent1, ticket1)
- assert(human_changes['Title'], 'Check if attributes translated based on ObjectManager::Attribute')
- assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
- assert_equal('2 normal', human_changes['Priority'][0])
- assert_equal('3 hoch', human_changes['Priority'][1])
- assert_equal('some notification template test old 1', human_changes['Title'][0])
- assert_equal('some notification template test 1 #2', human_changes['Title'][1])
- assert_not(human_changes['priority_id'])
- assert_not(human_changes['pending_time'])
- assert_not(human_changes['pending_till'])
- # de notification
- result = NotificationFactory::Mailer.template(
- locale: @agent1.preferences[:locale],
- timezone: @agent1.preferences[:timezone],
- template: 'ticket_update',
- objects: {
- ticket: ticket1,
- article: article,
- recipient: @agent1,
- changes: human_changes,
- }
- )
- assert_match(/Bobs's resumé/, result[:subject])
- assert_match(/Titel/, result[:body])
- assert_no_match(/Title/, result[:body])
- assert_match(/some notification template test old 1/, result[:body])
- assert_match(/some notification template test 1 #2/, result[:body])
- assert_match(/Priorität/, result[:body])
- assert_no_match(/Priority/, result[:body])
- assert_match(/3 hoch/, result[:body])
- assert_match(/2 normal/, result[:body])
- assert_match(/aktualisier/, result[:body])
- human_changes = bg.human_changes(@agent2, ticket1)
- # en notification
- result = NotificationFactory::Mailer.template(
- locale: @agent2.preferences[:locale],
- timezone: @agent2.preferences[:timezone],
- template: 'ticket_update',
- objects: {
- ticket: ticket1,
- article: article,
- recipient: @agent2,
- changes: human_changes,
- }
- )
- assert_match(/Bobs's resumé/, result[:subject])
- assert_match(/Title/, result[:body])
- assert_match(/some notification template test old 1/, result[:body])
- assert_match(/some notification template test 1 #2/, result[:body])
- assert_match(/Priority/, result[:body])
- assert_match(/3 high/, result[:body])
- assert_match(/2 normal/, result[:body])
- assert_no_match(/Pending till/, result[:body])
- assert_no_match(/2015-01-11 23:33:47 UTC/, result[:body])
- assert_match(/update/, result[:body])
- assert_no_match(/pending_till/, result[:body])
- assert_no_match(/i18n/, result[:body])
- # en notification
- ticket1.escalation_at = Time.zone.parse('2019-04-01T10:00:00Z')
- result = NotificationFactory::Mailer.template(
- locale: @agent2.preferences[:locale],
- timezone: @agent2.preferences[:timezone],
- template: 'ticket_escalation',
- objects: {
- ticket: ticket1,
- article: article,
- recipient: @agent2,
- }
- )
- assert_match('Ticket is escalated (some notification template test 1 Bobs\'s resumé', result[:subject])
- assert_match('is escalated since "04/01/2019 06:00 (America/St_Lucia)"!', result[:body])
- end
- end
|