Merge branch 'develop' of github.com:martini/zammad into develop

This commit is contained in:
Felix Niklas 2016-02-08 16:07:01 +01:00
commit 2542aa9b78
28 changed files with 880 additions and 206 deletions

View file

@ -11,7 +11,7 @@ class App.FirstStepsClues extends App.Controller
{ {
container: '.search-holder' container: '.search-holder'
headline: 'Search' headline: 'Search'
text: 'Here you can search for ticket, customers and organizations. To find everything use the §*§-Placeholder' text: 'Here you can search for ticket, customers and organizations. You can use the §*§-Placeholder as wildcard. E. g. §smi*§ or §rosent*l§. You also can use ||double quotes|| for searching phrases §"some phrase"§.'
} }
{ {
container: '.user-menu' container: '.user-menu'

View file

@ -11,56 +11,37 @@ class Index extends App.Controller
render: => render: =>
# matrix # matrix
config = {} config =
config['matrix'] = {} group_ids: []
config['matrix']['create'] = {} matrix:
config['matrix']['create']['name'] = 'new Ticket' create:
config['matrix']['create']['criteria'] = {} name: 'new Ticket'
config['matrix']['create']['criteria']['owned_by_me'] = true update:
config['matrix']['create']['criteria']['owned_by_nobody'] = true name: 'Ticket update'
config['matrix']['create']['criteria']['no'] = false reminder_reached:
config['matrix']['create']['channel'] = {} name: 'Ticket reminder reached'
config['matrix']['create']['channel']['email'] = true escalation:
config['matrix']['create']['channel']['online'] = false name: 'Ticket escalation'
config['matrix']['update'] = {}
config['matrix']['update']['name'] = 'Ticket update'
config['matrix']['update']['criteria'] = {}
config['matrix']['update']['criteria']['owned_by_me'] = true
config['matrix']['update']['criteria']['owned_by_nobody'] = false
config['matrix']['update']['criteria']['no'] = false
config['matrix']['update']['channel'] = {}
config['matrix']['update']['channel']['email'] = true
config['matrix']['update']['channel']['online'] = false
config['matrix']['move_into'] = {}
config['matrix']['move_into']['name'] = 'Ticket moved into my group'
config['matrix']['move_into']['criteria'] = {}
config['matrix']['move_into']['criteria']['owned_by_me'] = true
config['matrix']['move_into']['criteria']['owned_by_nobody'] = true
config['matrix']['move_into']['criteria']['no'] = false
config['matrix']['move_into']['channel'] = {}
config['matrix']['move_into']['channel']['email'] = true
config['matrix']['move_into']['channel']['online'] = false
config['matrix']['escalation'] = {}
config['matrix']['escalation']['name'] = 'Ticket escalation'
config['matrix']['escalation']['criteria'] = {}
config['matrix']['escalation']['criteria']['owned_by_me'] = true
config['matrix']['escalation']['criteria']['owned_by_nobody'] = true
config['matrix']['escalation']['criteria']['no'] = false
config['matrix']['escalation']['channel'] = {}
config['matrix']['escalation']['channel']['email'] = true
config['matrix']['escalation']['channel']['online'] = false
user_config = @Session.get('preferences').notification_config user_config = @Session.get('preferences').notification_config
if user_config if user_config
config = $.extend(true, {}, config, user_config) config = $.extend(true, {}, config, user_config)
console.log('oo', config)
# groups # groups
user_group_config = true
if !user_config || !user_config['group_ids'] || _.isEmpty(user_config['group_ids']) || user_config['group_ids'][0] is '-'
user_group_config = false
groups = [] groups = []
group_ids = @Session.get('group_ids') group_ids = @Session.get('group_ids')
if group_ids if group_ids
for group_id in group_ids for group_id in group_ids
group = App.Group.find(group_id) group = App.Group.find(group_id)
groups.push group groups.push group
if !user_group_config
if !config['group_ids']
config['group_ids'] = []
config['group_ids'].push group_id.toString()
@html App.view('profile/notification')( groups: groups, config: config ) @html App.view('profile/notification')( groups: groups, config: config )
@ -72,7 +53,6 @@ class Index extends App.Controller
params.notification_config = {} params.notification_config = {}
form_params = @formParam(e.target) form_params = @formParam(e.target)
console.log('P',form_params)
for key, value of form_params for key, value of form_params
if key is 'group_ids' if key is 'group_ids'
if typeof value isnt 'object' if typeof value isnt 'object'
@ -108,10 +88,10 @@ class Index extends App.Controller
else else
params.notification_config[area[0]][area[1]][area[2]] = { params.notification_config[area[0]][area[1]][area[2]] = {
email: true email: true
online: false online: true
} }
console.log('P2',params) if !params.notification_config.group_ids || _.isEmpty(params.notification_config.group_ids)
params.notification_config.group_ids = ['-']
@formDisable(e) @formDisable(e)
# get data # get data

View file

@ -2,7 +2,7 @@ class App.Dashboard extends App.Controller
clueAccess: true clueAccess: true
events: events:
'click .tabs .tab': 'toggle' 'click .tabs .tab': 'toggle'
'click .intro': 'clues' 'click .js-intro': 'clues'
constructor: -> constructor: ->
super super

View file

@ -186,7 +186,8 @@ class _i18nSingleton extends Spine.Module
# apply inline markup # apply inline markup
translated translated
.replace(/\*(.+?)\*/gm, '<b>$1</b>') .replace(/\|\|(.+?)\|\|/gm, '<i>$1</i>')
.replace(/\|(.+?)\|/gm, '<b>$1</b>')
.replace(/_(.+?)_/gm, '<u>$1</u>') .replace(/_(.+?)_/gm, '<u>$1</u>')
.replace(/§(.+?)§/gm, '<kbd>$1</kbd>') .replace(/§(.+?)§/gm, '<kbd>$1</kbd>')

View file

@ -22,7 +22,7 @@
<td><input type="checkbox" name="matrix.<%= key %>.criteria.owned_by_nobody" value="true" <% if value.criteria.owned_by_nobody: %>checked<% end %>/></td> <td><input type="checkbox" name="matrix.<%= key %>.criteria.owned_by_nobody" value="true" <% if value.criteria.owned_by_nobody: %>checked<% end %>/></td>
<td><input type="checkbox" name="matrix.<%= key %>.criteria.no" value="true" <% if value.criteria.no: %>checked<% end %>/></td> <td><input type="checkbox" name="matrix.<%= key %>.criteria.no" value="true" <% if value.criteria.no: %>checked<% end %>/></td>
<td><input type="radio" name="matrix.<%= key %>.channel" value="email" <% if value.channel.email: %>checked<% end %>/></td> <td><input type="radio" name="matrix.<%= key %>.channel" value="email" <% if value.channel.email: %>checked<% end %>/></td>
<td><input type="radio" name="matrix.<%= key %>.channel" value="online" <% if value.channel.online: %>checked<% end %>/></td> <td><input type="radio" name="matrix.<%= key %>.channel" value="online" <% if !value.channel.email && value.channel.online: %>checked<% end %>/></td>
</tr> </tr>
<% end %> <% end %>
<% end %> <% end %>
@ -31,7 +31,7 @@
<h3><%- @T( 'Groups' ) %></h3> <h3><%- @T( 'Groups' ) %></h3>
<%- @T('For "owned by nobody" and "no criteria" only notify about tickets in theres groups.') %>
<div class="settings-entry"> <div class="settings-entry">
<table class="table"> <table class="table">
<% if @groups: %> <% if @groups: %>

View file

@ -15,7 +15,7 @@ $navigationWidth: 260px;
$highlight-color: hsl(205,90%,60%); $highlight-color: hsl(205,90%,60%);
$largeScreenBreakpoint: 1280px; $largeScreenBreakpoint: 1260px;
html { html {
height: 100%; height: 100%;

View file

@ -8,6 +8,10 @@ process emails from STDIN
cat /path/to/mail.eml | rails r 'Channel::Driver::MailStdin.new' cat /path/to/mail.eml | rails r 'Channel::Driver::MailStdin.new'
e. g.
cat test/fixtures/mail1.box | rails r 'Channel::Driver::MailStdin.new'
=end =end
def initialize def initialize

View file

@ -13,7 +13,7 @@ class Observer::Ticket::Notification::BackgroundJob
end end
# find recipients # find recipients
recipients = [] recipients_and_channels = []
=begin =begin
# group of agents to work on # group of agents to work on
@ -43,15 +43,68 @@ class Observer::Ticket::Notification::BackgroundJob
end end
=end =end
if ticket.owner_id != 1 # loop through all users
recipients.push ticket.owner possible_recipients = ticket.agent_of_group
else if ticket.owner_id == 1
recipients = ticket.agent_of_group() possible_recipients.push ticket.owner
end end
already_checked_recipient_ids = {}
possible_recipients.each {|user|
next if already_checked_recipient_ids[user.id]
already_checked_recipient_ids[user.id] = true
next if !user.preferences
next if !user.preferences['notification_config']
matrix = user.preferences['notification_config']['matrix']
if ticket.owner_id != user.id
if user.preferences['notification_config']['group_ids'] ||
(user.preferences['notification_config']['group_ids'].class == Array && (!user.preferences['notification_config']['group_ids'].empty? || user.preferences['notification_config']['group_ids'][0] != '-'))
hit = false
user.preferences['notification_config']['group_ids'].each {|notify_group_id|
user.group_ids.each {|local_group_id|
if local_group_id.to_s == notify_group_id.to_s
hit = true
end
}
}
next if !hit
end
end
next if !matrix
next if !matrix[@p[:type]]
data = matrix[@p[:type]]
next if !data
next if !data['criteria']
channels = data['channel']
if data['criteria']['owned_by_me'] && ticket.owner_id == user.id
data = {
user: user,
channels: channels
}
recipients_and_channels.push data
next
end
if data['criteria']['owned_by_nobody'] && ticket.owner_id == 1
data = {
user: user,
channels: channels
}
recipients_and_channels.push data
next
end
next unless data['criteria']['no']
data = {
user: user,
channels: channels
}
recipients_and_channels.push data
next
}
# send notifications # send notifications
recipient_list = '' recipient_list = ''
recipients.each do |user| recipients_and_channels.each do |item|
user = item[:user]
channels = item[:channels]
# ignore user who changed it by him self via web # ignore user who changed it by him self via web
if @via_web if @via_web
@ -62,7 +115,14 @@ class Observer::Ticket::Notification::BackgroundJob
# ignore inactive users # ignore inactive users
next if !user.active next if !user.active
# ignore if no changes has been done
changes = human_changes(user, ticket)
next if @p[:type] == 'update' && !article && ( !changes || changes.empty? )
# create online notification # create online notification
used_channels = []
if channels['online']
used_channels.push 'online'
seen = ticket.online_notification_seen_state(user.id) seen = ticket.online_notification_seen_state(user.id)
OnlineNotification.add( OnlineNotification.add(
type: @p[:type], type: @p[:type],
@ -72,22 +132,18 @@ class Observer::Ticket::Notification::BackgroundJob
created_by_id: ticket.updated_by_id || 1, created_by_id: ticket.updated_by_id || 1,
user_id: user.id, user_id: user.id,
) )
Rails.logger.info "send ticket online notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
# create email notification
next if !user.email || user.email == ''
# add recipient_list
if recipient_list != ''
recipient_list += ','
end end
recipient_list += user.email.to_s
# ignore if no changes has been done # ignore email channel notificaiton and empty emails
changes = human_changes(user, ticket) if !channels['email'] || !user.email || user.email == ''
if @p[:type] == 'update' && !article && ( !changes || changes.empty? ) add_recipient_list(ticket, user, used_channels)
next next
end end
used_channels.push 'email'
add_recipient_list(ticket, user, used_channels)
# get user based notification template # get user based notification template
# if create, send create message / block update messages # if create, send create message / block update messages
if @p[:type] == 'create' if @p[:type] == 'create'
@ -115,8 +171,7 @@ class Observer::Ticket::Notification::BackgroundJob
# rebuild subject # rebuild subject
notification[:subject] = ticket.subject_build(notification[:subject]) notification[:subject] = ticket.subject_build(notification[:subject])
# send notification Rails.logger.info "send ticket email notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
Rails.logger.info "send ticket notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
NotificationFactory.send( NotificationFactory.send(
recipient: user, recipient: user,
@ -126,9 +181,15 @@ class Observer::Ticket::Notification::BackgroundJob
) )
end end
# add history record end
return if recipient_list == ''
def add_recipient_list(ticket, user, channels)
return if channels.empty?
identifier = user.email
if !identifier || identifier == ''
identifier = user.login
end
recipient_list = "#{identifier}(#{channels.join(',')})"
History.add( History.add(
o_id: ticket.id, o_id: ticket.id,
history_type: 'notification', history_type: 'notification',

View file

@ -11,9 +11,13 @@ add new file to store
store_file_id = Store::File.add(binary_data) store_file_id = Store::File.add(binary_data)
do also verify of written data
store_file_id = Store::File.add(binary_data, true)
=end =end
def self.add(data) def self.add(data, verify = true)
sha = Digest::SHA256.hexdigest(data) sha = Digest::SHA256.hexdigest(data)
file = Store::File.find_by(sha: sha) file = Store::File.find_by(sha: sha)
@ -30,6 +34,15 @@ add new file to store
provider: adapter_name, provider: adapter_name,
sha: sha, sha: sha,
) )
# verify
if verify
read_data = adapter.get(sha)
read_sha = Digest::SHA256.hexdigest(read_data)
if sha != read_sha
fail "Content not written correctly (provider #{adapter_name})."
end
end
end end
file file
end end

View file

@ -84,7 +84,12 @@ returns
=end =end
def agent_of_group def agent_of_group
Group.find( group_id ).users.where( active: true ).joins(:roles).where( 'roles.name' => Z_ROLENAME_AGENT, 'roles.active' => true ).uniq() Group.find(group_id)
.users.where(active: true)
.joins(:roles)
.where('roles.name' => Z_ROLENAME_AGENT, 'roles.active' => true)
.order('users.login')
.uniq()
end end
=begin =begin

View file

@ -29,15 +29,15 @@ class User < ApplicationModel
include User::Assets include User::Assets
extend User::Search extend User::Search
before_create :check_name, :check_email, :check_login, :check_password before_create :check_name, :check_email, :check_login, :check_password, :check_preferences_default
before_update :check_password, :check_email, :check_login before_update :check_password, :check_email, :check_login, :check_preferences_default
after_create :avatar_for_email_check after_create :avatar_for_email_check
after_update :avatar_for_email_check after_update :avatar_for_email_check
after_destroy :avatar_destroy after_destroy :avatar_destroy
notify_clients_support notify_clients_support
has_and_belongs_to_many :groups, after_add: :cache_update, after_remove: :cache_update has_and_belongs_to_many :groups, after_add: :cache_update, after_remove: :cache_update
has_and_belongs_to_many :roles, after_add: :cache_update, after_remove: :cache_update has_and_belongs_to_many :roles, after_add: [:cache_update, :check_notifications], after_remove: :cache_update
has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update
has_many :tokens, after_add: :cache_update, after_remove: :cache_update has_many :tokens, after_add: :cache_update, after_remove: :cache_update
has_many :authorizations, after_add: :cache_update, after_remove: :cache_update has_many :authorizations, after_add: :cache_update, after_remove: :cache_update
@ -451,7 +451,7 @@ returns
list of active users in role list of active users in role
result = User.of_role('Agent') result = User.of_role('Agent', group_ids)
returns returns
@ -459,9 +459,58 @@ returns
=end =end
def self.of_role(role) def self.of_role(role, group_ids = nil)
roles_ids = Role.where(active: true, name: role).map(&:id) roles_ids = Role.where(active: true, name: role).map(&:id)
User.where(active: true).joins(:users_roles).where('roles_users.role_id IN (?)', roles_ids) if !group_ids
return User.where(active: true).joins(:users_roles).where('roles_users.role_id IN (?)', roles_ids)
end
User.where(active: true)
.joins(:users_roles)
.joins(:users_groups)
.where('roles_users.role_id IN (?) AND users_groups.group_ids IN (?)', roles_ids, group_ids)
end
=begin
update/sync default preferences of users in a dedecated role
result = User.update_default_preferences('Agent')
returns
result = true # false
=end
def self.update_default_preferences(role_name)
role = Role.lookup(name: role_name)
User.of_role(role_name).each {|user|
user.check_notifications(role)
user.check_preferences_default
user.save
}
true
end
def check_notifications(o)
default = Rails.configuration.preferences_default_by_role
return if !default
default.deep_stringify_keys!
return if !default[o.name]
if !@preferences_default
@preferences_default = {}
end
default[o.name].each {|key, value|
next if @preferences_default[key]
@preferences_default[key] = value
}
end
def check_preferences_default
return if !@preferences_default
return if @preferences_default.empty?
preferences_tmp = @preferences_default.merge(preferences)
self.preferences = preferences_tmp
end end
private private
@ -605,4 +654,5 @@ returns
crypted = Digest::SHA2.hexdigest(password) crypted = Digest::SHA2.hexdigest(password)
self.password = "{sha2}#{crypted}" self.password = "{sha2}#{crypted}"
end end
end end

View file

@ -50,5 +50,58 @@ module Zammad
# define cache store # define cache store
config.cache_store = :file_store, "tmp/cache_file_store_#{Rails.env}" config.cache_store = :file_store, "tmp/cache_file_store_#{Rails.env}"
# default preferences by role
config.preferences_default_by_role = {
Agent: {
notification_config: {
matrix: {
create: {
criteria: {
owned_by_me: true,
owned_by_nobody: true,
no: false,
},
channel: {
email: true,
online: true,
}
},
update: {
criteria: {
owned_by_me: true,
owned_by_nobody: true,
no: false,
},
channel: {
email: true,
online: true,
}
},
reminder_reached: {
criteria: {
owned_by_me: true,
owned_by_nobody: false,
no: false,
},
channel: {
email: true,
online: true,
}
},
escalation: {
criteria: {
owned_by_me: true,
owned_by_nobody: false,
no: false,
},
channel: {
email: true,
online: true,
}
}
}
}
}
}
end end
end end

View file

@ -63,6 +63,7 @@ class CreateTicket < ActiveRecord::Migration
t.column :escalation_time, :timestamp, null: true t.column :escalation_time, :timestamp, null: true
t.column :pending_time, :timestamp, null: true t.column :pending_time, :timestamp, null: true
t.column :type, :string, limit: 100, null: true t.column :type, :string, limit: 100, null: true
t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
t.column :updated_by_id, :integer, null: false t.column :updated_by_id, :integer, null: false
t.column :created_by_id, :integer, null: false t.column :created_by_id, :integer, null: false
t.timestamps null: false t.timestamps null: false

View file

@ -60,9 +60,9 @@ class UpdateSettings4 < ActiveRecord::Migration
name: 'ticket_hook_position', name: 'ticket_hook_position',
tag: 'select', tag: 'select',
options: { options: {
'left' => 'Left', 'left' => 'left',
'right' => 'Right', 'right' => 'right',
'none' => 'None', 'none' => 'none',
}, },
}, },
], ],

View file

@ -77,6 +77,25 @@ class CreateChat < ActiveRecord::Migration
created_by_id: 1, created_by_id: 1,
) )
Scheduler.create_or_update(
name: 'Closed chat sessions where participients are offline.',
method: 'Chat.cleanup_close',
period: 60 * 15,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
Scheduler.create_or_update(
name: 'Cleanup closed sessions.',
method: 'Chat.cleanup',
period: 5.days,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
end end
def down def down

View file

@ -1,25 +0,0 @@
class UpdateChat4 < ActiveRecord::Migration
def up
Scheduler.create_or_update(
name: 'Closed chat sessions where participients are offline.',
method: 'Chat.cleanup_close',
period: 60 * 15,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
Scheduler.create_or_update(
name: 'Cleanup closed sessions.',
method: 'Chat.cleanup',
period: 5.days,
prio: 2,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
end
def down
end
end

View file

@ -1,5 +0,0 @@
class UpdateTicketPreferences < ActiveRecord::Migration
def up
add_column :tickets, :preferences, :text, limit: 500.kilobytes + 1, null: true
end
end

View file

@ -0,0 +1,5 @@
class UpdateDefaultPreferences < ActiveRecord::Migration
def up
User.update_default_preferences('Agent')
end
end

View file

@ -14,6 +14,7 @@ class Sessions::Backend::TicketOverviewList
overviews = Ticket::Overviews.all( overviews = Ticket::Overviews.all(
current_user: @user, current_user: @user,
) )
return if !overviews
result = [] result = []
overviews.each { |overview| overviews.each { |overview|
overview_data = Ticket::Overviews.list( overview_data = Ticket::Overviews.list(

View file

@ -274,9 +274,12 @@ test( "i18n", function() {
translated = App.i18n.translateContent('%s %s test', 123, 'xxx'); translated = App.i18n.translateContent('%s %s test', 123, 'xxx');
equal( translated, '123 xxx test', 'de-de - %s %s' ); equal( translated, '123 xxx test', 'de-de - %s %s' );
translated = App.i18n.translateContent('*%s* %s test', 123, 'xxx'); translated = App.i18n.translateContent('|%s| %s test', 123, 'xxx');
equal( translated, '<b>123</b> xxx test', 'de-de - *%s* %s' ); equal( translated, '<b>123</b> xxx test', 'de-de - *%s* %s' );
translated = App.i18n.translateContent('||%s|| %s test', 123, 'xxx');
equal( translated, '<i>123</i> xxx test', 'de-de - *%s* %s' );
translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx'); translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx');
equal( translated, '<u>123</u> xxx test', 'de-de - _%s_ %s' ); equal( translated, '<u>123</u> xxx test', 'de-de - _%s_ %s' );
@ -311,9 +314,12 @@ test( "i18n", function() {
translated = App.i18n.translateContent('%s %s test', 123, 'xxx'); translated = App.i18n.translateContent('%s %s test', 123, 'xxx');
equal( translated, '123 xxx test', 'en-us - %s %s' ); equal( translated, '123 xxx test', 'en-us - %s %s' );
translated = App.i18n.translateContent('*%s* %s test', 123, 'xxx'); translated = App.i18n.translateContent('|%s| %s test', 123, 'xxx');
equal( translated, '<b>123</b> xxx test', 'en-us - *%s* %s' ); equal( translated, '<b>123</b> xxx test', 'en-us - *%s* %s' );
translated = App.i18n.translateContent('||%s|| %s test', 123, 'xxx');
equal( translated, '<i>123</i> xxx test', 'en-us - *%s* %s' );
translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx'); translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx');
equal( translated, '<u>123</u> xxx test', 'en-us - _%s_ %s' ); equal( translated, '<u>123</u> xxx test', 'en-us - _%s_ %s' );

View file

@ -124,7 +124,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
Store.add( Store.add(
object: 'Ticket::Article', object: 'Ticket::Article',
o_id: article1.id, o_id: article1.id,
data: IO.read("#{Rails.root}/test/fixtures/es-normal.txt"), data: IO.binread("#{Rails.root}/test/fixtures/es-normal.txt"),
filename: 'es-normal.txt', filename: 'es-normal.txt',
preferences: {}, preferences: {},
created_by_id: 1, created_by_id: 1,
@ -135,7 +135,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
Store.add( Store.add(
object: 'Ticket::Article', object: 'Ticket::Article',
o_id: article1.id, o_id: article1.id,
data: IO.read("#{Rails.root}/test/fixtures/es-pdf1.pdf"), data: IO.binread("#{Rails.root}/test/fixtures/es-pdf1.pdf"),
filename: 'es-pdf1.pdf', filename: 'es-pdf1.pdf',
preferences: {}, preferences: {},
created_by_id: 1, created_by_id: 1,
@ -146,7 +146,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
Store.add( Store.add(
object: 'Ticket::Article', object: 'Ticket::Article',
o_id: article1.id, o_id: article1.id,
data: IO.read("#{Rails.root}/test/fixtures/es-box1.box"), data: IO.binread("#{Rails.root}/test/fixtures/es-box1.box"),
filename: 'mail1.box', filename: 'mail1.box',
preferences: {}, preferences: {},
created_by_id: 1, created_by_id: 1,
@ -157,7 +157,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
Store.add( Store.add(
object: 'Ticket::Article', object: 'Ticket::Article',
o_id: article1.id, o_id: article1.id,
data: IO.read("#{Rails.root}/test/fixtures/es-too-big.txt"), data: IO.binread("#{Rails.root}/test/fixtures/es-too-big.txt"),
filename: 'es-too-big.txt', filename: 'es-too-big.txt',
preferences: {}, preferences: {},
created_by_id: 1, created_by_id: 1,

View file

@ -459,11 +459,11 @@ class ZendeskImportTest < ActiveSupport::TestCase
escalation_time escalation_time
pending_time pending_time
type type
preferences
updated_by_id updated_by_id
created_by_id created_by_id
created_at created_at
updated_at updated_at)
preferences)
assert_equal( copmare_fields, local_fields, 'ticket fields' ) assert_equal( copmare_fields, local_fields, 'ticket fields' )
end end

View file

@ -6,7 +6,7 @@ class EmailParserTest < ActiveSupport::TestCase
test 'parse' do test 'parse' do
files = [ files = [
{ {
data: IO.read('test/fixtures/mail1.box'), data: IO.binread('test/fixtures/mail1.box'),
body_md5: 'b57d21dcac6b05e1aa67af51a9e4c1ec', body_md5: 'b57d21dcac6b05e1aa67af51a9e4c1ec',
params: { params: {
from: 'John.Smith@example.com', from: 'John.Smith@example.com',
@ -16,7 +16,7 @@ class EmailParserTest < ActiveSupport::TestCase
}, },
}, },
{ {
data: IO.read('test/fixtures/mail2.box'), data: IO.binread('test/fixtures/mail2.box'),
body_md5: '154c7d3ae7b94f99589df62882841b08', body_md5: '154c7d3ae7b94f99589df62882841b08',
params: { params: {
from: 'Martin Edenhofer <martin@example.com>', from: 'Martin Edenhofer <martin@example.com>',
@ -34,7 +34,7 @@ Old programmers never die. They just branch to a new address.
}, },
}, },
{ {
data: IO.read('test/fixtures/mail3.box'), data: IO.binread('test/fixtures/mail3.box'),
body_md5: '96a0a7847c1c60e82058db8f8bff8136', body_md5: '96a0a7847c1c60e82058db8f8bff8136',
params: { params: {
from: '"Günther John | Example GmbH" <k.guenther@example.com>', from: '"Günther John | Example GmbH" <k.guenther@example.com>',
@ -44,7 +44,7 @@ Old programmers never die. They just branch to a new address.
}, },
}, },
{ {
data: IO.read('test/fixtures/mail4.box'), data: IO.binread('test/fixtures/mail4.box'),
body_md5: '9fab9a0e8523011fde0f3ecd80f8d72c', body_md5: '9fab9a0e8523011fde0f3ecd80f8d72c',
params: { params: {
from: '"Günther Katja | Example GmbH" <k.guenther@example.com>', from: '"Günther Katja | Example GmbH" <k.guenther@example.com>',
@ -75,7 +75,7 @@ Liebe Grüße!
}, },
}, },
{ {
data: IO.read('test/fixtures/mail5.box'), data: IO.binread('test/fixtures/mail5.box'),
body_md5: 'f34033e9a34bb5367062dd5df21115df', body_md5: 'f34033e9a34bb5367062dd5df21115df',
params: { params: {
from: 'marc.smith@example.com (Marc Smith)', from: 'marc.smith@example.com (Marc Smith)',
@ -85,7 +85,7 @@ Liebe Grüße!
}, },
}, },
{ {
data: IO.read('test/fixtures/mail6.box'), data: IO.binread('test/fixtures/mail6.box'),
body_md5: '683ac042e94e99a8bb5e8ced7893b1d7', body_md5: '683ac042e94e99a8bb5e8ced7893b1d7',
params: { params: {
from: '"Hans BÄKOSchönland" <me@bogen.net>', from: '"Hans BÄKOSchönland" <me@bogen.net>',
@ -108,7 +108,7 @@ Test5:=
}, },
}, },
{ {
data: IO.read('test/fixtures/mail7.box'), data: IO.binread('test/fixtures/mail7.box'),
body_md5: 'c78f6a91905538ee32bc0bf71f70fcf2', body_md5: 'c78f6a91905538ee32bc0bf71f70fcf2',
params: { params: {
from: 'Eike.Ehringer@example.com', from: 'Eike.Ehringer@example.com',
@ -148,7 +148,7 @@ Managing Director: Martin Edenhofer",
}, },
}, },
{ {
data: IO.read('test/fixtures/mail8.box'), data: IO.binread('test/fixtures/mail8.box'),
body_md5: 'ca502c70a1b006f5184d1f0bf79d5799', body_md5: 'ca502c70a1b006f5184d1f0bf79d5799',
attachments: [ attachments: [
{ {
@ -188,7 +188,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail9.box'), data: IO.binread('test/fixtures/mail9.box'),
body_md5: 'c70de14cc69b17b07850b570d7a4fbe7', body_md5: 'c70de14cc69b17b07850b570d7a4fbe7',
attachments: [ attachments: [
{ {
@ -209,7 +209,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail10.box'), data: IO.binread('test/fixtures/mail10.box'),
body_md5: 'ddfad696bd34d83f607763180243f3c5', body_md5: 'ddfad696bd34d83f607763180243f3c5',
attachments: [ attachments: [
{ {
@ -230,7 +230,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail11.box'), data: IO.binread('test/fixtures/mail11.box'),
body_md5: 'cf8b26d9fc4ce9abb19a36ce3a130c79', body_md5: 'cf8b26d9fc4ce9abb19a36ce3a130c79',
attachments: [ attachments: [
{ {
@ -247,7 +247,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail12.box'), data: IO.binread('test/fixtures/mail12.box'),
body_md5: '8b48e082bc77e927d395448875259172', body_md5: '8b48e082bc77e927d395448875259172',
attachments: [ attachments: [
{ {
@ -268,7 +268,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail13.box'), data: IO.binread('test/fixtures/mail13.box'),
body_md5: '58806e006b14b04a535784a5462d09b0', body_md5: '58806e006b14b04a535784a5462d09b0',
attachments: [ attachments: [
{ {
@ -285,7 +285,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail14.box'), data: IO.binread('test/fixtures/mail14.box'),
body_md5: '154c7d3ae7b94f99589df62882841b08', body_md5: '154c7d3ae7b94f99589df62882841b08',
attachments: [ attachments: [
{ {
@ -307,7 +307,7 @@ Hof
}, },
# spam email # spam email
{ {
data: IO.read('test/fixtures/mail15.box'), data: IO.binread('test/fixtures/mail15.box'),
body_md5: '5872ddcdfdf6bfe40f36cd0408fca667', body_md5: '5872ddcdfdf6bfe40f36cd0408fca667',
attachments: [ attachments: [
# :preferences=>{"Message-ID"=>"<temp@test>", "Content-Type"=>"application/octet-stream; name=\"\xBC\xA8\xD0\xA7\xB9\xDC\xC0\xED,\xBE\xBF\xBE\xB9\xCB\xAD\xB4\xED\xC1\xCB.xls\"", "Mime-Type"=>"application/octet-stream", "Charset"=>"UTF-8"}} # :preferences=>{"Message-ID"=>"<temp@test>", "Content-Type"=>"application/octet-stream; name=\"\xBC\xA8\xD0\xA7\xB9\xDC\xC0\xED,\xBE\xBF\xBE\xB9\xCB\xAD\xB4\xED\xC1\xCB.xls\"", "Mime-Type"=>"application/octet-stream", "Charset"=>"UTF-8"}}
@ -327,7 +327,7 @@ Hof
}, },
# spam email # spam email
{ {
data: IO.read('test/fixtures/mail16.box'), data: IO.binread('test/fixtures/mail16.box'),
body_md5: '91e698a1ba3679dff398ba3587b3f3d9', body_md5: '91e698a1ba3679dff398ba3587b3f3d9',
params: { params: {
from: nil, from: nil,
@ -339,7 +339,7 @@ Hof
}, },
# spam email # spam email
{ {
data: IO.read('test/fixtures/mail17.box'), data: IO.binread('test/fixtures/mail17.box'),
body_md5: 'c32d6502f47435e613a2112625118270', body_md5: 'c32d6502f47435e613a2112625118270',
params: { params: {
from: '"都琹" <ghgbwum@185.com.cn>', from: '"都琹" <ghgbwum@185.com.cn>',
@ -350,7 +350,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail18.box'), data: IO.binread('test/fixtures/mail18.box'),
body_md5: '66f20e8557095762ccad9a6cb6f59c3a', body_md5: '66f20e8557095762ccad9a6cb6f59c3a',
params: { params: {
from: 'postmaster@example.com', from: 'postmaster@example.com',
@ -361,7 +361,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail19.box'), data: IO.binread('test/fixtures/mail19.box'),
body_md5: '0bf7e746158d121bce7e2c46b64b0d39', body_md5: '0bf7e746158d121bce7e2c46b64b0d39',
params: { params: {
from: '"我" <>', from: '"我" <>',
@ -372,7 +372,7 @@ Hof
}, },
}, },
{ {
data: IO.read('test/fixtures/mail20.box'), data: IO.binread('test/fixtures/mail20.box'),
body_md5: 'ddcbbb850491ae9a174c4f1e42309f84', body_md5: 'ddcbbb850491ae9a174c4f1e42309f84',
params: { params: {
from: 'Health and Care-Mall <drugs-cheapest8@sicor.com>', from: 'Health and Care-Mall <drugs-cheapest8@sicor.com>',
@ -413,7 +413,7 @@ Wade to give it seemed like this. Yeah but one for any longer. Everything you go
}, },
}, },
{ {
data: IO.read('test/fixtures/mail21.box'), data: IO.binread('test/fixtures/mail21.box'),
body_md5: 'c9fb828072385643e528ab3a9ce7f10c', body_md5: 'c9fb828072385643e528ab3a9ce7f10c',
params: { params: {
from: 'Viagra Super Force Online <pharmacy_affordable1@ertelecom.ru>', from: 'Viagra Super Force Online <pharmacy_affordable1@ertelecom.ru>',
@ -424,7 +424,7 @@ Wade to give it seemed like this. Yeah but one for any longer. Everything you go
}, },
}, },
{ {
data: IO.read('test/fixtures/mail22.box'), data: IO.binread('test/fixtures/mail22.box'),
body_md5: '7dd64b40dce1aa3053fc7bbdea136612', body_md5: '7dd64b40dce1aa3053fc7bbdea136612',
params: { params: {
from: 'Gilbertina Suthar <ireoniqla@lipetsk.ru>', from: 'Gilbertina Suthar <ireoniqla@lipetsk.ru>',
@ -454,7 +454,7 @@ Freemont and pulling out several minutes.
}, },
{ {
data: IO.read('test/fixtures/mail23.box'), data: IO.binread('test/fixtures/mail23.box'),
body_md5: '545a1b067fd10ac636c20b44f5df8868', body_md5: '545a1b067fd10ac636c20b44f5df8868',
params: { params: {
from: 'marketingmanager@nthcpghana.com', from: 'marketingmanager@nthcpghana.com',
@ -465,7 +465,7 @@ Freemont and pulling out several minutes.
}, },
}, },
{ {
data: IO.read('test/fixtures/mail24.box'), data: IO.binread('test/fixtures/mail24.box'),
body_md5: '5872ddcdfdf6bfe40f36cd0408fca667', body_md5: '5872ddcdfdf6bfe40f36cd0408fca667',
params: { params: {
from: 'oracle@IG0-1-DB01.example.com', from: 'oracle@IG0-1-DB01.example.com',
@ -486,7 +486,7 @@ Freemont and pulling out several minutes.
], ],
}, },
{ {
data: IO.read('test/fixtures/mail25.box'), data: IO.binread('test/fixtures/mail25.box'),
body_md5: '436f71d8d8a4ffbd3f18fc9de7d7f767', body_md5: '436f71d8d8a4ffbd3f18fc9de7d7f767',
params: { params: {
from: 'oracle@IG0-1-DB01.example.com', from: 'oracle@IG0-1-DB01.example.com',
@ -504,7 +504,7 @@ end
}, },
}, },
{ {
data: IO.read('test/fixtures/mail26.box'), data: IO.binread('test/fixtures/mail26.box'),
body_md5: 'c68fd31c71a463c7ea820ccdf672c680', body_md5: 'c68fd31c71a463c7ea820ccdf672c680',
params: { params: {
from: 'gate <team@support.gate.de>', from: 'gate <team@support.gate.de>',
@ -534,7 +534,7 @@ gate GmbH * Gladbacher Str. 74 * 40219 Düsseldorf
], ],
}, },
{ {
data: IO.read('test/fixtures/mail27.box'), data: IO.binread('test/fixtures/mail27.box'),
body_md5: 'd41d8cd98f00b204e9800998ecf8427e', body_md5: 'd41d8cd98f00b204e9800998ecf8427e',
params: { params: {
from: 'caoyaoewfzfw@21cn.com', from: 'caoyaoewfzfw@21cn.com',
@ -552,7 +552,7 @@ gate GmbH * Gladbacher Str. 74 * 40219 Düsseldorf
], ],
}, },
{ {
data: IO.read('test/fixtures/mail28.box'), data: IO.binread('test/fixtures/mail28.box'),
body_md5: '5872ddcdfdf6bfe40f36cd0408fca667', body_md5: '5872ddcdfdf6bfe40f36cd0408fca667',
params: { params: {
from: 'kontakt@example.de', from: 'kontakt@example.de',
@ -574,7 +574,7 @@ gate GmbH * Gladbacher Str. 74 * 40219 Düsseldorf
], ],
}, },
{ {
data: IO.read('test/fixtures/mail29.box'), data: IO.binread('test/fixtures/mail29.box'),
body_md5: 'bd34701dd5246b7651f67aeea6dd0fd3', body_md5: 'bd34701dd5246b7651f67aeea6dd0fd3',
params: { params: {
from: 'Example Sales <sales@example.com>', from: 'Example Sales <sales@example.com>',
@ -605,7 +605,7 @@ Registration AG Ulm HRB 534075 * General Manager Holger Felgner
}, },
}, },
{ {
data: IO.read('test/fixtures/mail30.box'), data: IO.binread('test/fixtures/mail30.box'),
body_md5: 'b4038e70d25854a023bce604c9f7a7ff', body_md5: 'b4038e70d25854a023bce604c9f7a7ff',
params: { params: {
from: 'Manfred Haert <Manfred.Haert@example.com>', from: 'Manfred Haert <Manfred.Haert@example.com>',
@ -651,7 +651,7 @@ Weil wir die Echtheit oder Vollständigkeit der in dieser Nachricht enthaltenen
}, },
}, },
{ {
data: IO.read('test/fixtures/mail31.box'), data: IO.binread('test/fixtures/mail31.box'),
body_md5: '10484f3b096e85e7001da387c18871d5', body_md5: '10484f3b096e85e7001da387c18871d5',
params: { params: {
from: '"bertha mou" <zhengkang@ha.chinamobile.com>', from: '"bertha mou" <zhengkang@ha.chinamobile.com>',
@ -662,7 +662,7 @@ Weil wir die Echtheit oder Vollständigkeit der in dieser Nachricht enthaltenen
}, },
}, },
{ {
data: IO.read('test/fixtures/mail32.box'), data: IO.binread('test/fixtures/mail32.box'),
body_md5: '6bed82e0d079e521f506e4e5d3529107', body_md5: '6bed82e0d079e521f506e4e5d3529107',
params: { params: {
from: '"Dana.Qin" <Dana.Qin6e1@gmail.com>', from: '"Dana.Qin" <Dana.Qin6e1@gmail.com>',
@ -673,7 +673,7 @@ Weil wir die Echtheit oder Vollständigkeit der in dieser Nachricht enthaltenen
}, },
}, },
{ {
data: IO.read('test/fixtures/mail34.box'), data: IO.binread('test/fixtures/mail34.box'),
body_md5: 'b6e46176404ec81b3ab412fe71dff0f0', body_md5: 'b6e46176404ec81b3ab412fe71dff0f0',
params: { params: {
from: 'Bay <memberbay+12345@members.somewhat>', from: 'Bay <memberbay+12345@members.somewhat>',
@ -685,7 +685,7 @@ Weil wir die Echtheit oder Vollständigkeit der in dieser Nachricht enthaltenen
}, },
}, },
{ {
data: IO.read('test/fixtures/mail36.box'), data: IO.binread('test/fixtures/mail36.box'),
body_md5: '428327fb533b387b3efca181ae0c25d0', body_md5: '428327fb533b387b3efca181ae0c25d0',
params: { params: {
from: 'Martin Smith <m.Smith@example.com>', from: 'Martin Smith <m.Smith@example.com>',

View file

@ -28,7 +28,7 @@ class EmailProcessBounceTest < ActiveSupport::TestCase
created_by_id: 1, created_by_id: 1,
) )
sleep 1 sleep 1
email_raw_string = IO.read('test/fixtures/mail33-undelivered-mail-returned-to-sender.box') 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) ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string)
assert_equal(ticket.id, ticket_p.id) assert_equal(ticket.id, ticket_p.id)
assert_equal('new', ticket_p.state.name) assert_equal('new', ticket_p.state.name)

View file

@ -131,7 +131,7 @@ Some Text",
}, },
}, },
{ {
data: IO.read('test/fixtures/mail21.box'), data: IO.binread('test/fixtures/mail21.box'),
success: true, success: true,
result: { result: {
0 => { 0 => {
@ -184,7 +184,7 @@ ___
}, },
}, },
{ {
data: IO.read('test/fixtures/mail22.box'), data: IO.binread('test/fixtures/mail22.box'),
success: true, success: true,
result: { result: {
0 => { 0 => {
@ -217,7 +217,7 @@ Freemont and pulling out several minutes.
}, },
}, },
{ {
data: IO.read('test/fixtures/mail23.box'), data: IO.binread('test/fixtures/mail23.box'),
success: true, success: true,
result: { result: {
0 => { 0 => {
@ -1870,7 +1870,7 @@ Some Text',
} }
}, },
{ {
data: IO.read('test/fixtures/mail30.box'), data: IO.binread('test/fixtures/mail30.box'),
success: true, success: true,
result: { result: {
0 => { 0 => {
@ -1906,7 +1906,7 @@ Some Text',
} }
}, },
{ {
data: IO.read('test/fixtures/mail31.box'), data: IO.binread('test/fixtures/mail31.box'),
success: true, success: true,
result: { result: {
0 => { 0 => {
@ -1930,7 +1930,7 @@ Some Text',
} }
}, },
{ {
data: IO.read('test/fixtures/mail32.box'), data: IO.binread('test/fixtures/mail32.box'),
success: true, success: true,
result: { result: {
0 => { 0 => {
@ -1954,7 +1954,7 @@ Some Text',
} }
}, },
{ {
data: IO.read('test/fixtures/mail35.box'), data: IO.binread('test/fixtures/mail35.box'),
success: true, success: true,
result: { result: {
0 => { 0 => {

View file

@ -15,12 +15,12 @@ class StoreTest < ActiveSupport::TestCase
o_id: 2, o_id: 2,
}, },
{ {
data: IO.read('test/fixtures/test1.pdf'), data: IO.binread('test/fixtures/test1.pdf'),
filename: 'test.pdf', filename: 'test.pdf',
o_id: 3, o_id: 3,
}, },
{ {
data: IO.read('test/fixtures/test1.pdf'), data: IO.binread('test/fixtures/test1.pdf'),
filename: 'test-again.pdf', filename: 'test-again.pdf',
o_id: 4, o_id: 4,
}, },

View file

@ -92,8 +92,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2 # verify notifications to agent1 + agent2
assert_equal(1, notification_check(ticket1, agent1), ticket1.id) assert_equal(1, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(1, notification_check(ticket1, agent2), ticket1.id) assert_equal(1, notification_check(ticket1, agent2, 'email'), ticket1.id)
# create ticket in group # create ticket in group
ticket1 = Ticket.create( ticket1 = Ticket.create(
@ -127,8 +127,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2 # verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket1, agent1), ticket1.id) assert_equal(0, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(1, notification_check(ticket1, agent2), ticket1.id) assert_equal(1, notification_check(ticket1, agent2, 'email'), ticket1.id)
end end
test 'ticket notification - simple' do test 'ticket notification - simple' do
@ -165,8 +165,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2 # verify notifications to agent1 + agent2
assert_equal(1, notification_check(ticket1, agent1), ticket1.id) assert_equal(1, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(1, notification_check(ticket1, agent2), ticket1.id) assert_equal(1, notification_check(ticket1, agent2, 'email'), ticket1.id)
# update ticket attributes # update ticket attributes
ticket1.title = "#{ticket1.title} - #2" ticket1.title = "#{ticket1.title} - #2"
@ -179,8 +179,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2 # verify notifications to agent1 + agent2
assert_equal(2, notification_check(ticket1, agent1), ticket1.id) assert_equal(2, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(2, notification_check(ticket1, agent2), ticket1.id) assert_equal(2, notification_check(ticket1, agent2, 'email'), ticket1.id)
# add article to ticket # add article to ticket
Ticket::Article.create( Ticket::Article.create(
@ -201,8 +201,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to not to agent1 but to agent2 # verify notifications to not to agent1 but to agent2
assert_equal(2, notification_check(ticket1, agent1), ticket1.id) assert_equal(2, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(3, notification_check(ticket1, agent2), ticket1.id) assert_equal(3, notification_check(ticket1, agent2, 'email'), ticket1.id)
# update ticket by user # update ticket by user
ticket1.owner_id = agent1.id ticket1.owner_id = agent1.id
@ -226,8 +226,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to not to agent1 but to agent2 # verify notifications to not to agent1 but to agent2
assert_equal(2, notification_check(ticket1, agent1), ticket1.id) assert_equal(2, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(3, notification_check(ticket1, agent2), ticket1.id) assert_equal(3, notification_check(ticket1, agent2, 'email'), ticket1.id)
# create ticket with agent1 as owner # create ticket with agent1 as owner
ticket2 = Ticket.create( ticket2 = Ticket.create(
@ -261,8 +261,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
assert(ticket2, 'ticket created') assert(ticket2, 'ticket created')
# verify notifications to no one # verify notifications to no one
assert_equal(0, notification_check(ticket2, agent1), ticket2.id) assert_equal(0, notification_check(ticket2, agent1, 'email'), ticket2.id)
assert_equal(0, notification_check(ticket2, agent2), ticket2.id) assert_equal(0, notification_check(ticket2, agent2, 'email'), ticket2.id)
# update ticket # update ticket
ticket2.title = "#{ticket2.title} - #2" ticket2.title = "#{ticket2.title} - #2"
@ -276,8 +276,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to no one # verify notifications to no one
assert_equal(0, notification_check(ticket2, agent1), ticket2.id) assert_equal(0, notification_check(ticket2, agent1, 'email'), ticket2.id)
assert_equal(0, notification_check(ticket2, agent2), ticket2.id) assert_equal(0, notification_check(ticket2, agent2, 'email'), ticket2.id)
# update ticket # update ticket
ticket2.title = "#{ticket2.title} - #3" ticket2.title = "#{ticket2.title} - #3"
@ -291,8 +291,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to agent1 and not to agent2 # verify notifications to agent1 and not to agent2
assert_equal(1, notification_check(ticket2, agent1), ticket2.id) assert_equal(1, notification_check(ticket2, agent1, 'email'), ticket2.id)
assert_equal(0, notification_check(ticket2, agent2), ticket2.id) assert_equal(0, notification_check(ticket2, agent2, 'email'), ticket2.id)
# create ticket with agent2 and agent1 as owner # create ticket with agent2 and agent1 as owner
ticket3 = Ticket.create( ticket3 = Ticket.create(
@ -326,8 +326,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
assert(ticket3, 'ticket created') assert(ticket3, 'ticket created')
# verify notifications to agent1 and not to agent2 # verify notifications to agent1 and not to agent2
assert_equal(1, notification_check(ticket3, agent1), ticket3.id) assert_equal(1, notification_check(ticket3, agent1, 'email'), ticket3.id)
assert_equal(0, notification_check(ticket3, agent2), ticket3.id) assert_equal(0, notification_check(ticket3, agent2, 'email'), ticket3.id)
# update ticket # update ticket
ticket3.title = "#{ticket3.title} - #2" ticket3.title = "#{ticket3.title} - #2"
@ -341,8 +341,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to no one # verify notifications to no one
assert_equal(1, notification_check(ticket3, agent1), ticket3.id) assert_equal(1, notification_check(ticket3, agent1, 'email'), ticket3.id)
assert_equal(0, notification_check(ticket3, agent2), ticket3.id) assert_equal(0, notification_check(ticket3, agent2, 'email'), ticket3.id)
# update ticket # update ticket
ticket3.title = "#{ticket3.title} - #3" ticket3.title = "#{ticket3.title} - #3"
@ -356,8 +356,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications to agent1 and not to agent2 # verify notifications to agent1 and not to agent2
assert_equal(2, notification_check(ticket3, agent1), ticket3.id) assert_equal(2, notification_check(ticket3, agent1, 'email'), ticket3.id)
assert_equal(0, notification_check(ticket3, agent2), ticket3.id) assert_equal(0, notification_check(ticket3, agent2, 'email'), ticket3.id)
# update article / not notification should be sent # update article / not notification should be sent
article_inbound.internal = true article_inbound.internal = true
@ -369,8 +369,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
# verify notifications not to agent1 and not to agent2 # verify notifications not to agent1 and not to agent2
assert_equal(2, notification_check(ticket3, agent1), ticket3.id) assert_equal(2, notification_check(ticket3, agent1, 'email'), ticket3.id)
assert_equal(0, notification_check(ticket3, agent2), ticket3.id) assert_equal(0, notification_check(ticket3, agent2, 'email'), ticket3.id)
delete = ticket1.destroy delete = ticket1.destroy
assert(delete, 'ticket1 destroy') assert(delete, 'ticket1 destroy')
@ -383,6 +383,452 @@ class TicketNotificationTest < ActiveSupport::TestCase
end 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
ticket1 = Ticket.create(
title: 'some notification test - z preferences tests 1',
group: Group.lookup(name: 'Users'),
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 ticket events
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(1, notification_check(ticket1, agent2, 'email'), ticket1.id)
# update ticket attributes
ticket1.title = "#{ticket1.title} - #2"
ticket1.priority = Ticket::Priority.lookup(name: '3 high')
ticket1.save
# execute ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket1, agent1, 'email'), ticket1.id)
assert_equal(2, notification_check(ticket1, agent2, 'email'), ticket1.id)
# create ticket in group
ticket2 = Ticket.create(
title: 'some notification test - z preferences tests 2',
group: Group.lookup(name: 'Users'),
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 ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(1, notification_check(ticket2, agent1, 'email'), ticket2.id)
assert_equal(1, notification_check(ticket2, agent2, 'email'), ticket2.id)
# update ticket attributes
ticket2.title = "#{ticket2.title} - #2"
ticket2.priority = Ticket::Priority.lookup(name: '3 high')
ticket2.save
# execute ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(2, notification_check(ticket2, agent1, 'email'), ticket2.id)
assert_equal(2, notification_check(ticket2, agent2, 'email'), ticket2.id)
# create ticket in group
ticket3 = Ticket.create(
title: 'some notification test - z preferences tests 3',
group: Group.lookup(name: 'Users'),
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 ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket3, agent1, 'email'), ticket3.id)
assert_equal(1, notification_check(ticket3, agent2, 'email'), ticket3.id)
# update ticket attributes
ticket3.title = "#{ticket3.title} - #2"
ticket3.priority = Ticket::Priority.lookup(name: '3 high')
ticket3.save
# execute ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket3, agent1, 'email'), ticket3.id)
assert_equal(2, notification_check(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: 'Users').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
# create ticket in group
ticket4 = Ticket.create(
title: 'some notification test - z preferences tests 4',
group: Group.lookup(name: 'Users'),
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 ticket events
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(1, notification_check(ticket4, agent1, 'email'), ticket4.id)
assert_equal(1, notification_check(ticket4, agent2, 'email'), ticket4.id)
# update ticket attributes
ticket4.title = "#{ticket4.title} - #2"
ticket4.priority = Ticket::Priority.lookup(name: '3 high')
ticket4.save
# execute ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(2, notification_check(ticket4, agent1, 'email'), ticket4.id)
assert_equal(2, notification_check(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: 'Users').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
# create ticket in group
ticket5 = Ticket.create(
title: 'some notification test - z preferences tests 5',
group: Group.lookup(name: 'Users'),
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 ticket events
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(1, notification_check(ticket5, agent1, 'email'), ticket5.id)
assert_equal(0, notification_check(ticket5, agent2, 'email'), ticket5.id)
# update ticket attributes
ticket5.title = "#{ticket5.title} - #2"
ticket5.priority = Ticket::Priority.lookup(name: '3 high')
ticket5.save
# execute ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(2, notification_check(ticket5, agent1, 'email'), ticket5.id)
assert_equal(0, notification_check(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
# create ticket in group
ticket6 = Ticket.create(
title: 'some notification test - z preferences tests 6',
group: Group.lookup(name: 'Users'),
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 ticket events
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(1, notification_check(ticket6, agent1, 'email'), ticket6.id)
assert_equal(1, notification_check(ticket6, agent1, 'online'), ticket6.id)
assert_equal(0, notification_check(ticket6, agent2, 'email'), ticket6.id)
assert_equal(0, notification_check(ticket6, agent2, 'online'), ticket6.id)
# update ticket attributes
ticket6.title = "#{ticket6.title} - #2"
ticket6.priority = Ticket::Priority.lookup(name: '3 high')
ticket6.save
# execute ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(2, notification_check(ticket6, agent1, 'email'), ticket6.id)
assert_equal(2, notification_check(ticket6, agent1, 'online'), ticket6.id)
assert_equal(0, notification_check(ticket6, agent2, 'email'), ticket6.id)
assert_equal(0, notification_check(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
# create ticket in group
ticket7 = Ticket.create(
title: 'some notification test - z preferences tests 7',
group: Group.lookup(name: 'Users'),
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 ticket events
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket7, agent1, 'email'), ticket7.id)
assert_equal(1, notification_check(ticket7, agent1, 'online'), ticket7.id)
assert_equal(0, notification_check(ticket7, agent2, 'email'), ticket7.id)
assert_equal(0, notification_check(ticket7, agent2, 'online'), ticket7.id)
# update ticket attributes
ticket7.title = "#{ticket7.title} - #2"
ticket7.priority = Ticket::Priority.lookup(name: '3 high')
ticket7.save
# execute ticket events
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket7, agent1, 'email'), ticket7.id)
assert_equal(2, notification_check(ticket7, agent1, 'online'), ticket7.id)
assert_equal(0, notification_check(ticket7, agent2, 'email'), ticket7.id)
assert_equal(0, notification_check(ticket7, agent2, 'online'), ticket7.id)
end
test 'ticket notification events' do test 'ticket notification events' do
# create ticket in group # create ticket in group
@ -607,13 +1053,14 @@ class TicketNotificationTest < ActiveSupport::TestCase
end end
def notification_check(ticket, recipient) def notification_check(ticket, recipient, type)
result = ticket.history_get() result = ticket.history_get()
count = 0 count = 0
result.each {|item| result.each {|item|
next if item['type'] != 'notification' next if item['type'] != 'notification'
next if item['object'] != 'Ticket' next if item['object'] != 'Ticket'
next if item['value_to'] !~ /#{recipient.email}/i next if item['value_to'] !~ /#{recipient.email}/i
next if item['value_to'] !~ /#{type}/i
count += 1 count += 1
} }
count count

View file

@ -287,4 +287,62 @@ class UserTest < ActiveSupport::TestCase
user.destroy user.destroy
} }
end end
test 'user default preferences' do
groups = Group.where(name: 'Users')
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
login: 'agent-default-preferences1@example.com',
firstname: 'Preferences',
lastname: 'Agent1',
email: 'agent-default-preferences1@example.com',
password: 'agentpw',
active: true,
roles: roles,
groups: groups,
preferences: {
locale: 'de-de',
},
updated_by_id: 1,
created_by_id: 1,
)
assert(agent1.preferences)
assert(agent1.preferences['locale'])
assert_equal(agent1.preferences['locale'], 'de-de')
assert(agent1.preferences['notification_config'])
assert(agent1.preferences['notification_config']['matrix'])
assert(agent1.preferences['notification_config']['matrix']['create'])
assert(agent1.preferences['notification_config']['matrix']['update'])
roles = Role.where(name: 'Customer')
customer1 = User.create_or_update(
login: 'customer-default-preferences1@example.com',
firstname: 'Preferences',
lastname: 'Customer1',
email: 'customer-default-preferences1@example.com',
password: 'customerpw',
active: true,
roles: roles,
preferences: {
locale: 'de-de',
},
updated_by_id: 1,
created_by_id: 1,
)
assert(customer1.preferences)
assert(customer1.preferences['locale'])
assert_equal(customer1.preferences['locale'], 'de-de')
assert_not(customer1.preferences['notification_config'])
customer1.roles = Role.where(name: 'Agent')
customer1.save
assert(customer1.preferences)
assert(customer1.preferences['locale'])
assert_equal(customer1.preferences['locale'], 'de-de')
assert(customer1.preferences['notification_config'])
assert(customer1.preferences['notification_config']['matrix']['create'])
assert(customer1.preferences['notification_config']['matrix']['update'])
end
end end