Moved to init prepare/setup method for tests.

This commit is contained in:
Martin Edenhofer 2016-06-20 10:55:45 +02:00
parent 1e2f1da0aa
commit 3c523b4f7d
12 changed files with 793 additions and 725 deletions

View file

@ -2,6 +2,10 @@
require 'test_helper'
class ActivityStreamTest < ActiveSupport::TestCase
admin_user = nil
current_user = nil
activity_record_delay = nil
test 'aaa - setup' do
role = Role.lookup(name: 'Admin')
group = Group.lookup(name: 'Users')
admin_user = User.create_or_update(
@ -23,6 +27,7 @@ class ActivityStreamTest < ActiveSupport::TestCase
else
90.seconds
end
end
test 'ticket+user' do
tests = [

View file

@ -155,8 +155,8 @@ class AutoWizardTest < ActiveSupport::TestCase
{
id: 1,
channel_id: 1,
realname: 'some realname',
email: 'helpdesk@example.com',
realname: 'Zammad',
email: 'zammad@localhost',
}
],
}

View file

@ -2,6 +2,9 @@
require 'test_helper'
class ChatTest < ActiveSupport::TestCase
agent1 = nil
agent2 = nil
test 'aaa - setup' do
# create base
groups = Group.all
@ -32,6 +35,7 @@ class ChatTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
end
test 'default test' do

View file

@ -2,8 +2,17 @@
require 'test_helper'
class OnlineNotificationTest < ActiveSupport::TestCase
group = nil
agent_user1 = nil
agent_user2 = nil
customer_user = nil
test 'aaa - setup' do
role = Role.lookup(name: 'Agent')
group = Group.lookup(name: 'Users')
group = Group.create_or_update(
name: 'OnlineNotificationTest',
updated_by_id: 1,
created_by_id: 1
)
agent_user1 = User.create_or_update(
login: 'agent_online_notify1',
firstname: 'Bob',
@ -29,6 +38,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
created_by_id: 1
)
customer_user = User.lookup(email: 'nicole.braun@zammad.org')
end
test 'ticket notification' do
@ -36,7 +46,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# case #1
ticket1 = Ticket.create(
group_id: Group.lookup(name: 'Users').id,
group: group,
customer_id: customer_user.id,
owner_id: User.lookup(login: '-').id,
title: 'Unit Test 1 (äöüß)!',
@ -91,7 +101,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# case #2
ticket2 = Ticket.create(
group_id: Group.lookup(name: 'Users').id,
group: group,
customer_id: customer_user.id,
owner_id: agent_user1.id,
title: 'Unit Test 1 (äöüß)!',
@ -146,7 +156,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# case #3
ticket3 = Ticket.create(
group_id: Group.lookup(name: 'Users').id,
group: group,
customer_id: customer_user.id,
owner_id: User.lookup(login: '-').id,
title: 'Unit Test 2 (äöüß)!',
@ -226,7 +236,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# case #4
ticket4 = Ticket.create(
group_id: Group.lookup(name: 'Users').id,
group: group,
customer_id: customer_user.id,
owner_id: agent_user1.id,
title: 'Unit Test 3 (äöüß)!',
@ -280,7 +290,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# case #5
ticket5 = Ticket.create(
group_id: Group.lookup(name: 'Users').id,
group: group,
customer_id: customer_user.id,
owner_id: User.lookup(login: '-').id,
title: 'Unit Test 4 (äöüß)!',
@ -364,7 +374,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
test 'ticket notification item check' do
ticket1 = Ticket.create(
title: 'some title',
group: Group.lookup(name: 'Users'),
group: group,
customer_id: customer_user.id,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),

View file

@ -2,10 +2,15 @@
require 'test_helper'
class OrganizationRefObjectTouchTest < ActiveSupport::TestCase
agent1 = nil
organization1 = nil
customer1 = nil
customer2 = nil
test 'aaa - setup' do
# create base
groups = Group.where( name: 'Users' )
roles = Role.where( name: 'Agent' )
groups = Group.where(name: 'Users')
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
login: 'organization-ref-object-update-agent1@example.com',
firstname: 'Notification',
@ -19,7 +24,7 @@ class OrganizationRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where( name: 'Customer' )
roles = Role.where(name: 'Customer')
organization1 = Organization.create_if_not_exists(
name: 'Ref Object Update Org 1',
updated_at: '2015-02-05 16:37:00',
@ -58,22 +63,23 @@ class OrganizationRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
end
test 'a - check if ticket and customer has been updated' do
test 'b - check if ticket and customer has been updated' do
ticket = Ticket.create(
title: "some title1\n äöüß",
group: Group.lookup( name: 'Users'),
group: Group.lookup(name: 'Users'),
customer_id: customer1.id,
owner_id: agent1.id,
state: Ticket::State.lookup( name: 'new' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1,
created_by_id: 1,
)
assert(ticket, 'ticket created')
assert_equal(ticket.customer.id, customer1.id )
assert_equal(ticket.organization.id, organization1.id )
assert_equal(ticket.customer.id, customer1.id)
assert_equal(ticket.organization.id, organization1.id)
sleep 4

View file

@ -2,13 +2,14 @@
require 'test_helper'
class SessionBasicTest < ActiveSupport::TestCase
test 'aaa - setup' do
user = User.lookup(id: 1)
roles = Role.where(name: %w(Agent Admin))
user.roles = roles
user.save
end
test 'a cache' do
test 'b cache' do
Sessions::CacheIn.set('last_run_test', true, { expires_in: 1.second })
result = Sessions::CacheIn.get('last_run_test')
assert_equal(true, result, 'check 1')

View file

@ -2,10 +2,14 @@
require 'test_helper'
class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
agent1 = nil
organization1 = nil
customer1 = nil
test 'aaa - setup' do
# create base
groups = Group.where( name: 'Users' )
roles = Role.where( name: 'Agent' )
groups = Group.where(name: 'Users')
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
login: 'ticket-customer-organization-update-agent1@example.com',
firstname: 'Notification',
@ -19,7 +23,7 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where( name: 'Customer' )
roles = Role.where(name: 'Customer')
organization1 = Organization.create_if_not_exists(
name: 'Customer Organization Update',
updated_at: '2015-02-05 16:37:00',
@ -39,22 +43,23 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
end
test 'create ticket, update customers organization later' do
ticket = Ticket.create(
title: "some title1\n äöüß",
group: Group.lookup( name: 'Users'),
group: Group.lookup(name: 'Users'),
customer_id: customer1.id,
owner_id: agent1.id,
state: Ticket::State.lookup( name: 'new' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1,
created_by_id: 1,
)
assert( ticket, 'ticket created' )
assert_equal( customer1.id, ticket.customer.id )
assert_equal( organization1.id, ticket.organization.id )
assert(ticket, 'ticket created')
assert_equal(customer1.id, ticket.customer.id)
assert_equal(organization1.id, ticket.organization.id)
# update customer organization
customer1.organization_id = nil
@ -62,7 +67,7 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
# verify ticket
ticket = Ticket.find(ticket.id)
assert_equal( nil, ticket.organization_id )
assert_equal(nil, ticket.organization_id)
# update customer organization
customer1.organization_id = organization1.id
@ -70,7 +75,7 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
# verify ticket
ticket = Ticket.find(ticket.id)
assert_equal( organization1.id, ticket.organization_id )
assert_equal(organization1.id, ticket.organization_id)
ticket.destroy
end

View file

@ -2,7 +2,10 @@
require 'test_helper'
class TicketNotificationTest < ActiveSupport::TestCase
agent1 = nil
agent2 = nil
customer = nil
test 'aaa - setup' do
Trigger.create_or_update(
name: 'auto reply - new ticket',
condition: {
@ -43,7 +46,12 @@ class TicketNotificationTest < ActiveSupport::TestCase
)
# create agent1 & agent2
groups = Group.where(name: 'Users')
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',
@ -96,13 +104,14 @@ class TicketNotificationTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
end
test 'ticket notification - to all agents / to explicit agents' do
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification test 1',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
@ -135,8 +144,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification test 1',
group: Group.lookup(name: 'Users'),
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'),
@ -172,8 +181,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification test 1',
group: Group.lookup(name: 'Users'),
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'),
@ -264,8 +273,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket with agent1 as owner
ticket2 = Ticket.create(
title: 'some notification test 2',
group: Group.lookup(name: 'Users'),
title: 'some notification test 4',
group: Group.lookup(name: 'TicketNotificationTest'),
customer_id: 2,
owner_id: agent1.id,
state: Ticket::State.lookup(name: 'new'),
@ -326,8 +335,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket with agent2 and agent1 as owner
ticket3 = Ticket.create(
title: 'some notification test 3',
group: Group.lookup(name: 'Users'),
title: 'some notification test 5',
group: Group.lookup(name: 'TicketNotificationTest'),
customer_id: 2,
owner_id: agent1.id,
state: Ticket::State.lookup(name: 'new'),
@ -414,7 +423,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification test 1 - no notification',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
@ -467,7 +476,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification test - z preferences tests 1',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
@ -513,7 +522,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket2 = Ticket.create(
title: 'some notification test - z preferences tests 2',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
owner: agent1,
state: Ticket::State.lookup(name: 'new'),
@ -559,7 +568,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket3 = Ticket.create(
title: 'some notification test - z preferences tests 3',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
owner: agent2,
state: Ticket::State.lookup(name: 'new'),
@ -608,7 +617,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
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.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
@ -623,7 +632,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket4 = Ticket.create(
title: 'some notification test - z preferences tests 4',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
@ -672,7 +681,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
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.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
@ -687,7 +696,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket5 = Ticket.create(
title: 'some notification test - z preferences tests 5',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
@ -751,7 +760,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket6 = Ticket.create(
title: 'some notification test - z preferences tests 6',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
owner: agent1,
state: Ticket::State.lookup(name: 'new'),
@ -828,7 +837,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket7 = Ticket.create(
title: 'some notification test - z preferences tests 7',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
owner: agent1,
state: Ticket::State.lookup(name: 'new'),
@ -883,7 +892,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification event test 1',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
@ -943,7 +952,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification template test 1 Bobs\'s resumé',
group: Group.lookup(name: 'Users'),
group: Group.lookup(name: 'TicketNotificationTest'),
customer: customer,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),

View file

@ -2,6 +2,13 @@
require 'test_helper'
class TicketOverviewTest < ActiveSupport::TestCase
agent1 = nil
agent2 = nil
organization_id = nil
customer1 = nil
customer2 = nil
customer3 = nil
test 'aaa - setup' do
# create base
group = Group.create_or_update(
@ -273,6 +280,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
view_mode_default: 's',
},
)
end
test 'ticket create' do

View file

@ -2,10 +2,15 @@
require 'test_helper'
class TicketRefObjectTouchTest < ActiveSupport::TestCase
agent1 = nil
organization1 = nil
customer1 = nil
customer2 = nil
test 'aaa - setup' do
# create base
groups = Group.where( name: 'Users' )
roles = Role.where( name: 'Agent' )
groups = Group.where(name: 'Users')
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
login: 'ticket-ref-object-update-agent1@example.com',
firstname: 'Notification',
@ -19,7 +24,7 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where( name: 'Customer' )
roles = Role.where(name: 'Customer')
organization1 = Organization.create_if_not_exists(
name: 'Ref Object Update Org',
updated_at: '2015-02-05 16:37:00',
@ -52,8 +57,9 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
end
test 'a - check if customer and organization has been updated' do
test 'b - check if customer and organization has been updated' do
ticket = Ticket.create(
title: "some title1\n äöüß",
@ -66,8 +72,8 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase
created_by_id: 1,
)
assert(ticket, 'ticket created')
assert_equal(ticket.customer.id, customer1.id )
assert_equal(ticket.organization.id, organization1.id )
assert_equal(ticket.customer.id, customer1.id)
assert_equal(ticket.organization.id, organization1.id)
# check if customer and organization has been touched
customer1 = User.find(customer1.id)
@ -105,7 +111,7 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase
end
end
test 'b - check if customer (not organization) has been updated' do
test 'c - check if customer (not organization) has been updated' do
sleep 6
ticket = Ticket.create(

View file

@ -2,6 +2,13 @@
require 'test_helper'
class TicketSelectorTest < ActiveSupport::TestCase
agent1 = nil
agent2 = nil
group = nil
organization1 = nil
customer1 = nil
customer2 = nil
test 'aaa - setup' do
# create base
group = Group.create_or_update(
@ -72,6 +79,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
)
Ticket.where(group_id: group.id).destroy_all
end
test 'ticket create' do

View file

@ -2,6 +2,11 @@
require 'test_helper'
class UserRefObjectTouchTest < ActiveSupport::TestCase
agent1 = nil
organization1 = nil
customer1 = nil
customer2 = nil
test 'aaa - setup' do
# create base
groups = Group.where(name: 'Users')
@ -52,8 +57,9 @@ class UserRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
end
test 'a - check if ticket and organization has been updated' do
test 'b - check if ticket and organization has been updated' do
ticket = Ticket.create(
title: "some title1\n äöüß",