From aa51a9a5dc2dae1f517a5c4e6ec3000d35fc3a58 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 21 Jan 2015 21:45:22 +0100 Subject: [PATCH] Fixed user who initiate the notification. --- .../ticket/notification/background_job.rb | 2 +- test/unit/online_notifiaction_test.rb | 142 ++++++++++++++++++ 2 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 test/unit/online_notifiaction_test.rb diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index cafc133fd..c285f05c1 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -69,7 +69,7 @@ class Observer::Ticket::Notification::BackgroundJob :object => 'Ticket', :o_id => ticket.id, :seen => false, - :created_by_id => ticket.created_by_id || 1, + :created_by_id => ticket.updated_by_id || 1, :user_id => user.id, ) diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb new file mode 100644 index 000000000..53d2231e7 --- /dev/null +++ b/test/unit/online_notifiaction_test.rb @@ -0,0 +1,142 @@ +# encoding: utf-8 +require 'test_helper' + +class OnlineNotificationTest < ActiveSupport::TestCase + role = Role.lookup( :name => 'Agent' ) + group = Group.lookup( :name => 'Users' ) + agent_user1 = User.create_or_update( + :login => 'agent_online_notify1', + :firstname => 'Bob', + :lastname => 'Smith', + :email => 'agent_online_notify1@example.com', + :password => 'some_pass', + :active => true, + :role_ids => [role.id], + :group_ids => [group.id], + :updated_by_id => 1, + :created_by_id => 1 + ) + agent_user2 = User.create_or_update( + :login => 'agent_online_notify2', + :firstname => 'Bob', + :lastname => 'Smith', + :email => 'agent_online_notify2@example.com', + :password => 'some_pass', + :active => true, + :role_ids => [role.id], + :group_ids => [group.id], + :updated_by_id => 1, + :created_by_id => 1 + ) + customer_user = User.lookup( :login => 'nicole.braun@zammad.org' ) + + test 'ticket notifiaction' do + tests = [ + + # test 1 + { + :create => { + :ticket => { + :group_id => Group.lookup( :name => 'Users' ).id, + :customer_id => customer_user.id, + :owner_id => User.lookup( :login => '-' ).id, + :title => 'Unit Test 1 (äöüß)!', + :state_id => Ticket::State.lookup( :name => 'new' ).id, + :priority_id => Ticket::Priority.lookup( :name => '2 normal' ).id, + :updated_by_id => agent_user1.id, + :created_by_id => agent_user1.id, + }, + :article => { + :updated_by_id => agent_user1.id, + :created_by_id => agent_user1.id, + :type_id => Ticket::Article::Type.lookup( :name => 'phone' ).id, + :sender_id => Ticket::Article::Sender.lookup( :name => 'Customer' ).id, + :from => 'Unit Test ', + :body => 'Unit Test 123', + :internal => false + }, + }, + :update => { + :ticket => { + :title => 'Unit Test 1 (äöüß) - update!', + :state_id => Ticket::State.lookup( :name => 'open' ).id, + :priority_id => Ticket::Priority.lookup( :name => '1 low' ).id, + :updated_by_id => customer_user.id, + }, + }, + :check => [ + { + :type => 'create', + :object => 'Ticket', + :created_by_id => agent_user1.id, + }, + { + :type => 'update', + :object => 'Ticket', + :created_by_id => customer_user.id, + }, + ] + }, + ] + tickets = [] + tests.each { |test| + + ticket = Ticket.create( test[:create][:ticket] ) + test[:check][0][:o_id] = ticket.id + test[:check][1][:o_id] = ticket.id + + test[:create][:article][:ticket_id] = ticket.id + article = Ticket::Article.create( test[:create][:article] ) + + assert_equal( ticket.class.to_s, 'Ticket' ) + + # execute ticket events + Observer::Ticket::Notification.transaction + #puts Delayed::Job.all.inspect + Delayed::Worker.new.work_off + + # update ticket + if test[:update][:ticket] + ticket.update_attributes( test[:update][:ticket] ) + end + + # execute ticket events + Observer::Ticket::Notification.transaction + #puts Delayed::Job.all.inspect + Delayed::Worker.new.work_off + + # remember ticket + tickets.push ticket + + # check online notifications + notification_check( OnlineNotification.list(agent_user2, 10), test[:check] ) + } + + # delete tickets + tickets.each { |ticket| + ticket_id = ticket.id + ticket.destroy + found = Ticket.where( :id => ticket_id ).first + assert( !found, "Ticket destroyed") + } + end + + def notification_check( onine_notifications, checks ) + checks.each { |check_item| + hit = false + onine_notifications.each {|onine_notification| + if onine_notification['o_id'] == check_item[:o_id] + if onine_notification['object'] == check_item[:object] + if onine_notification['type'] == check_item[:type] + if onine_notification['created_by_id'] == check_item[:created_by_id] + hit = true + end + end + end + end + } + assert( hit, "online notification exists #{ check_item.inspect }" ) + } + end + +end \ No newline at end of file