2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2013-09-28 00:07:11 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ActivityStreamTest < ActiveSupport::TestCase
|
2017-06-14 15:25:45 +00:00
|
|
|
|
2021-07-09 13:05:05 +00:00
|
|
|
setup do
|
2017-11-23 08:09:44 +00:00
|
|
|
roles = Role.where(name: %w[Admin Agent])
|
2017-06-14 15:25:45 +00:00
|
|
|
groups = Group.where(name: 'Users')
|
|
|
|
@admin_user = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'admin',
|
|
|
|
firstname: 'Bob',
|
|
|
|
lastname: 'Smith',
|
|
|
|
email: 'bob+active_stream@example.com',
|
|
|
|
password: 'some_pass',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2016-06-20 08:55:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
@current_user = User.lookup(email: 'nicole.braun@zammad.org')
|
|
|
|
ActivityStream.delete_all
|
2016-06-20 08:55:45 +00:00
|
|
|
end
|
2016-04-13 07:30:44 +00:00
|
|
|
|
2013-09-28 00:07:11 +00:00
|
|
|
test 'ticket+user' do
|
2017-07-14 22:35:44 +00:00
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
group_id: Group.lookup(name: 'Users').id,
|
|
|
|
customer_id: @current_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,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @current_user.id,
|
|
|
|
created_by_id: @current_user.id,
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
|
|
|
travel 2.seconds
|
|
|
|
|
2017-07-14 22:35:44 +00:00
|
|
|
article = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket.id,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @current_user.id,
|
|
|
|
created_by_id: @current_user.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
type_id: Ticket::Article::Type.lookup(name: 'phone').id,
|
|
|
|
sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
|
|
|
|
from: 'Unit Test <unittest@example.com>',
|
|
|
|
body: 'Unit Test 123',
|
|
|
|
internal: false,
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
2014-06-26 22:42:27 +00:00
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
travel 100.seconds
|
2017-09-11 11:16:08 +00:00
|
|
|
ticket.update!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'Unit Test 1 (äöüß) - update!',
|
|
|
|
state_id: Ticket::State.lookup(name: 'open').id,
|
2016-12-08 14:06:54 +00:00
|
|
|
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
|
|
|
)
|
|
|
|
updated_at = ticket.updated_at
|
2013-09-28 00:07:11 +00:00
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
travel 1.second
|
2017-09-11 11:16:08 +00:00
|
|
|
ticket.update!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'Unit Test 2 (äöüß) - update!',
|
2016-12-08 14:06:54 +00:00
|
|
|
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
|
|
|
)
|
2013-09-28 00:07:11 +00:00
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
# check activity_stream
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @admin_user.activity_stream(4)
|
2018-03-20 12:16:17 +00:00
|
|
|
assert_equal(stream[0].group_id, ticket.group_id)
|
|
|
|
assert_equal(stream[0].o_id, ticket.id)
|
|
|
|
assert_equal(stream[0].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[0].created_at.to_s, updated_at.to_s)
|
|
|
|
assert_equal(stream[0].object.name, 'Ticket')
|
|
|
|
assert_equal(stream[0].type.name, 'update')
|
|
|
|
assert_equal(stream[1].group_id, ticket.group_id)
|
|
|
|
assert_equal(stream[1].o_id, article.id)
|
|
|
|
assert_equal(stream[1].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[1].created_at.to_s, article.created_at.to_s)
|
|
|
|
assert_equal(stream[1].object.name, 'Ticket::Article')
|
|
|
|
assert_equal(stream[1].type.name, 'create')
|
|
|
|
assert_equal(stream[2].group_id, ticket.group_id)
|
|
|
|
assert_equal(stream[2].o_id, ticket.id)
|
|
|
|
assert_equal(stream[2].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[2].created_at.to_s, ticket.created_at.to_s)
|
|
|
|
assert_equal(stream[2].object.name, 'Ticket')
|
|
|
|
assert_equal(stream[2].type.name, 'create')
|
2016-12-08 14:06:54 +00:00
|
|
|
assert_not(stream[3])
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @current_user.activity_stream(4)
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(stream.blank?)
|
2016-12-08 14:06:54 +00:00
|
|
|
|
2018-02-20 04:30:46 +00:00
|
|
|
# delete article and check if entry has gone
|
|
|
|
article.destroy!
|
|
|
|
|
|
|
|
# check activity_stream
|
|
|
|
stream = @admin_user.activity_stream(4)
|
2018-03-20 12:16:17 +00:00
|
|
|
assert_equal(stream[0].group_id, ticket.group_id)
|
|
|
|
assert_equal(stream[0].o_id, ticket.id)
|
|
|
|
assert_equal(stream[0].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[0].created_at.to_s, updated_at.to_s)
|
|
|
|
assert_equal(stream[0].object.name, 'Ticket')
|
|
|
|
assert_equal(stream[0].type.name, 'update')
|
|
|
|
assert_equal(stream[1].group_id, ticket.group_id)
|
|
|
|
assert_equal(stream[1].o_id, ticket.id)
|
|
|
|
assert_equal(stream[1].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[1].created_at.to_s, ticket.created_at.to_s)
|
|
|
|
assert_equal(stream[1].object.name, 'Ticket')
|
|
|
|
assert_equal(stream[1].type.name, 'create')
|
2018-02-20 04:30:46 +00:00
|
|
|
assert_not(stream[2])
|
|
|
|
|
|
|
|
stream = @current_user.activity_stream(4)
|
|
|
|
assert(stream.blank?)
|
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
# cleanup
|
2017-07-14 22:35:44 +00:00
|
|
|
ticket.destroy!
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2013-09-28 00:07:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'organization' do
|
2017-07-14 22:35:44 +00:00
|
|
|
organization = Organization.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'some name',
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @current_user.id,
|
|
|
|
created_by_id: @current_user.id,
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
|
|
|
travel 100.seconds
|
|
|
|
assert_equal(organization.class, Organization)
|
|
|
|
|
2017-09-11 11:16:08 +00:00
|
|
|
organization.update!(name: 'some name (äöüß)')
|
2016-12-08 14:06:54 +00:00
|
|
|
updated_at = organization.updated_at
|
|
|
|
|
|
|
|
travel 10.seconds
|
2017-09-11 11:16:08 +00:00
|
|
|
organization.update!(name: 'some name 2 (äöüß)')
|
2016-12-08 14:06:54 +00:00
|
|
|
|
|
|
|
# check activity_stream
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @admin_user.activity_stream(3)
|
2018-03-20 12:16:17 +00:00
|
|
|
assert_not(stream[0].group_id)
|
|
|
|
assert_equal(stream[0].o_id, organization.id)
|
|
|
|
assert_equal(stream[0].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[0].created_at.to_s, updated_at.to_s)
|
|
|
|
assert_equal(stream[0].object.name, 'Organization')
|
|
|
|
assert_equal(stream[0].type.name, 'update')
|
|
|
|
assert_not(stream[1].group_id)
|
|
|
|
assert_equal(stream[1].o_id, organization.id)
|
|
|
|
assert_equal(stream[1].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[1].created_at.to_s, organization.created_at.to_s)
|
|
|
|
assert_equal(stream[1].object.name, 'Organization')
|
|
|
|
assert_equal(stream[1].type.name, 'create')
|
2016-12-08 14:06:54 +00:00
|
|
|
assert_not(stream[2])
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @current_user.activity_stream(4)
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(stream.blank?)
|
2016-12-08 14:06:54 +00:00
|
|
|
|
|
|
|
# cleanup
|
2017-07-14 22:35:44 +00:00
|
|
|
organization.destroy!
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2013-09-28 00:07:11 +00:00
|
|
|
end
|
|
|
|
|
2013-10-05 12:56:03 +00:00
|
|
|
test 'user with update check false' do
|
2017-07-14 22:35:44 +00:00
|
|
|
user = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'someemail@example.com',
|
|
|
|
email: 'someemail@example.com',
|
|
|
|
firstname: 'Bob Smith II',
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @current_user.id,
|
|
|
|
created_by_id: @current_user.id,
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
|
|
|
assert_equal(user.class, User)
|
2017-09-11 11:16:08 +00:00
|
|
|
user.update!(
|
2016-12-08 14:06:54 +00:00
|
|
|
firstname: 'Bob U',
|
2018-12-19 17:31:51 +00:00
|
|
|
lastname: 'Smith U',
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
2013-10-05 12:56:03 +00:00
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
# check activity_stream
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @admin_user.activity_stream(3)
|
2018-03-20 12:16:17 +00:00
|
|
|
assert_not(stream[0].group_id)
|
|
|
|
assert_equal(stream[0].o_id, user.id)
|
|
|
|
assert_equal(stream[0].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[0].created_at.to_s, user.created_at.to_s)
|
|
|
|
assert_equal(stream[0].object.name, 'User')
|
|
|
|
assert_equal(stream[0].type.name, 'create')
|
2016-12-08 14:06:54 +00:00
|
|
|
assert_not(stream[1])
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @current_user.activity_stream(4)
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(stream.blank?)
|
2016-12-08 14:06:54 +00:00
|
|
|
|
|
|
|
# cleanup
|
2017-07-14 22:35:44 +00:00
|
|
|
user.destroy!
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2013-10-05 12:56:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'user with update check true' do
|
2017-07-14 22:35:44 +00:00
|
|
|
user = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'someemail@example.com',
|
|
|
|
email: 'someemail@example.com',
|
|
|
|
firstname: 'Bob Smith II',
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: @current_user.id,
|
|
|
|
created_by_id: @current_user.id,
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
|
|
|
travel 100.seconds
|
|
|
|
assert_equal(user.class, User)
|
2013-10-05 12:56:03 +00:00
|
|
|
|
2017-09-11 11:16:08 +00:00
|
|
|
user.update!(
|
2016-12-08 14:06:54 +00:00
|
|
|
firstname: 'Bob U',
|
2018-12-19 17:31:51 +00:00
|
|
|
lastname: 'Smith U',
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
|
|
|
updated_at = user.updated_at
|
2013-10-05 12:56:03 +00:00
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
travel 10.seconds
|
2017-09-11 11:16:08 +00:00
|
|
|
user.update!(
|
2016-12-08 14:06:54 +00:00
|
|
|
firstname: 'Bob',
|
2018-12-19 17:31:51 +00:00
|
|
|
lastname: 'Smith',
|
2016-12-08 14:06:54 +00:00
|
|
|
)
|
2014-06-26 22:42:27 +00:00
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
# check activity_stream
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @admin_user.activity_stream(3)
|
2018-03-20 12:16:17 +00:00
|
|
|
assert_not(stream[0].group_id)
|
|
|
|
assert_equal(stream[0].o_id, user.id)
|
|
|
|
assert_equal(stream[0].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[0].created_at.to_s, updated_at.to_s)
|
|
|
|
assert_equal(stream[0].object.name, 'User')
|
|
|
|
assert_equal(stream[0].type.name, 'update')
|
|
|
|
assert_not(stream[1].group_id)
|
|
|
|
assert_equal(stream[1].o_id, user.id)
|
|
|
|
assert_equal(stream[1].created_by_id, @current_user.id)
|
|
|
|
assert_equal(stream[1].created_at.to_s, user.created_at.to_s)
|
|
|
|
assert_equal(stream[1].object.name, 'User')
|
|
|
|
assert_equal(stream[1].type.name, 'create')
|
2016-12-08 14:06:54 +00:00
|
|
|
assert_not(stream[2])
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
stream = @current_user.activity_stream(4)
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(stream.blank?)
|
2016-12-08 14:06:54 +00:00
|
|
|
|
|
|
|
# cleanup
|
2017-07-14 22:35:44 +00:00
|
|
|
user.destroy!
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2013-09-28 00:07:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|