Improved tests.

This commit is contained in:
Martin Edenhofer 2016-02-26 13:56:36 +01:00
parent 9084c99d4b
commit 2575abf380

View file

@ -27,8 +27,8 @@ class TicketTest < ActiveSupport::TestCase
message_id: 'some@id', message_id: 'some@id',
body: 'some message article_inbound1 😍😍😍', body: 'some message article_inbound1 😍😍😍',
internal: false, internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first, sender: Ticket::Article::Sender.find_by(name: 'Customer'),
type: Ticket::Article::Type.where(name: 'email').first, type: Ticket::Article::Type.find_by(name: 'email'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ -52,8 +52,8 @@ class TicketTest < ActiveSupport::TestCase
message_id: 'some@id', message_id: 'some@id',
body: 'some message article_inbound2 😍😍😍', body: 'some message article_inbound2 😍😍😍',
internal: false, internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first, sender: Ticket::Article::Sender.find_by(name: 'Customer'),
type: Ticket::Article::Type.where(name: 'email').first, type: Ticket::Article::Type.find_by(name: 'email'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ -74,8 +74,8 @@ class TicketTest < ActiveSupport::TestCase
subject: "some\nnote", subject: "some\nnote",
body: "some\n message", body: "some\n message",
internal: true, internal: true,
sender: Ticket::Article::Sender.where(name: 'Agent').first, sender: Ticket::Article::Sender.find_by(name: 'Agent'),
type: Ticket::Article::Type.where(name: 'note').first, type: Ticket::Article::Type.find_by(name: 'note'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ -100,8 +100,8 @@ class TicketTest < ActiveSupport::TestCase
message_id: 'some@id2', message_id: 'some@id2',
body: 'some message 2', body: 'some message 2',
internal: false, internal: false,
sender: Ticket::Article::Sender.where(name: 'Agent').first, sender: Ticket::Article::Sender.find_by(name: 'Agent'),
type: Ticket::Article::Type.where(name: 'email').first, type: Ticket::Article::Type.find_by(name: 'email'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ -123,8 +123,8 @@ class TicketTest < ActiveSupport::TestCase
message_id: 'some@id', message_id: 'some@id',
body: 'some message article_inbound3 😍😍😍', body: 'some message article_inbound3 😍😍😍',
internal: false, internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first, sender: Ticket::Article::Sender.find_by(name: 'Customer'),
type: Ticket::Article::Type.where(name: 'email').first, type: Ticket::Article::Type.find_by(name: 'email'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ -148,8 +148,8 @@ class TicketTest < ActiveSupport::TestCase
message_id: 'some@id', message_id: 'some@id',
body: 'some message article_inbound4 😍😍😍', body: 'some message article_inbound4 😍😍😍',
internal: false, internal: false,
sender: Ticket::Article::Sender.where(name: 'Customer').first, sender: Ticket::Article::Sender.find_by(name: 'Customer'),
type: Ticket::Article::Type.where(name: 'email').first, type: Ticket::Article::Type.find_by(name: 'email'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ -175,7 +175,7 @@ class TicketTest < ActiveSupport::TestCase
assert(ticket.close_time, 'ticket.close_time verify - state update') assert(ticket.close_time, 'ticket.close_time verify - state update')
# set pending time # set pending time
ticket.state_id = Ticket::State.where(name: 'pending reminder').first.id ticket.state_id = Ticket::State.find_by(name: 'pending reminder').id
ticket.pending_time = Time.zone.parse('1977-10-27 22:00:00 +0000') ticket.pending_time = Time.zone.parse('1977-10-27 22:00:00 +0000')
ticket.save ticket.save
@ -184,7 +184,7 @@ class TicketTest < ActiveSupport::TestCase
assert_equal(ticket.pending_time, Time.zone.parse('1977-10-27 22:00:00 +0000'), 'pending_time verify') assert_equal(ticket.pending_time, Time.zone.parse('1977-10-27 22:00:00 +0000'), 'pending_time verify')
# reset pending state, should also reset pending time # reset pending state, should also reset pending time
ticket.state_id = Ticket::State.where(name: 'closed').first.id ticket.state_id = Ticket::State.find_by(name: 'closed').id
ticket.save ticket.save
ticket = Ticket.find(ticket.id) ticket = Ticket.find(ticket.id)
@ -238,6 +238,12 @@ class TicketTest < ActiveSupport::TestCase
test 'ticket process_pending' do test 'ticket process_pending' do
# close all other pending close tickets first
Ticket.where('pending_time IS NOT NULL').each {|ticket|
ticket.state = Ticket::State.lookup(name: 'closed')
ticket.save!
}
ticket = Ticket.create( ticket = Ticket.create(
title: 'pending close test', title: 'pending close test',
group: Group.lookup(name: 'Users'), group: Group.lookup(name: 'Users'),
@ -250,13 +256,11 @@ class TicketTest < ActiveSupport::TestCase
) )
lookup_ticket = Ticket.find_by('pending_time <= ?', Time.zone.now) lookup_ticket = Ticket.find_by('pending_time <= ?', Time.zone.now)
assert_equal(lookup_ticket.id, ticket.id, 'ticket.pending_time verify') assert_equal(lookup_ticket.id, ticket.id, 'ticket.pending_time verify')
Ticket.process_pending Ticket.process_pending
lookup_ticket = Ticket.find_by('pending_time <= ?', Time.zone.now) lookup_ticket = Ticket.find_by('pending_time <= ?', Time.zone.now)
assert_nil(lookup_ticket, 'ticket.pending_time processed verify') assert_nil(lookup_ticket, 'ticket.pending_time processed verify')
end end
end end