Refactoring: Migrate ticket_state_change to RSpec
This commit is contained in:
parent
153032e82f
commit
914f2f313f
2 changed files with 14 additions and 125 deletions
|
@ -259,8 +259,8 @@ RSpec.describe Ticket, type: :model do
|
|||
|
||||
describe 'Attributes:' do
|
||||
describe '#state' do
|
||||
context 'for brand new tickets' do
|
||||
context 'when a non-customer article is added' do
|
||||
context 'when originally "new"' do
|
||||
context 'and a non-customer article is added' do
|
||||
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
||||
|
||||
it 'switches to "open"' do
|
||||
|
@ -268,6 +268,18 @@ RSpec.describe Ticket, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when originally "closed"' do
|
||||
before { ticket.update(state: Ticket::State.find_by(name: 'closed')) }
|
||||
|
||||
context 'when a non-customer article is added' do
|
||||
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
|
||||
|
||||
it 'stays "closed"' do
|
||||
expect { article }.not_to change { ticket.state.name }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#pending_time' do
|
||||
|
@ -472,5 +484,4 @@ RSpec.describe Ticket, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class TicketStateChangeTest < ActiveSupport::TestCase
|
||||
|
||||
test 'check if after reply ticket is open' do
|
||||
|
||||
ticket1 = Ticket.create!(
|
||||
title: 'com test 1',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer_id: 2,
|
||||
state: Ticket::State.lookup(name: 'new'),
|
||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert(ticket1, 'ticket created')
|
||||
|
||||
article1 = Ticket::Article.create!(
|
||||
ticket_id: ticket1.id,
|
||||
from: 'some_customer_com-1@example.com',
|
||||
to: 'some_zammad_com-1@example.com',
|
||||
subject: 'com test 1',
|
||||
message_id: 'some@id_com_1',
|
||||
body: 'some message 123',
|
||||
internal: false,
|
||||
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
||||
type: Ticket::Article::Type.find_by(name: 'email'),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
||||
Observer::Transaction.commit
|
||||
Scheduler.worker(true)
|
||||
|
||||
ticket1.reload
|
||||
assert_equal('new', ticket1.state.name)
|
||||
|
||||
ticket1.with_lock do
|
||||
ticket1.update!(state_id: Ticket::State.find_by(name: 'new').id)
|
||||
article2 = Ticket::Article.create!(
|
||||
ticket_id: ticket1.id,
|
||||
from: 'some_zammad_com-1@example.com',
|
||||
to: 'some_customer_com-1@example.com',
|
||||
subject: 'com test 1',
|
||||
message_id: 'some@id_com_2',
|
||||
body: 'some message 123',
|
||||
internal: false,
|
||||
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
||||
type: Ticket::Article::Type.find_by(name: 'email'),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
end
|
||||
|
||||
Observer::Transaction.commit
|
||||
Scheduler.worker(true)
|
||||
|
||||
ticket1.reload
|
||||
assert_equal('open', ticket1.state.name)
|
||||
|
||||
end
|
||||
|
||||
test 'check if after reply ticket is closed' do
|
||||
|
||||
ticket1 = Ticket.create!(
|
||||
title: 'com test 1',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer_id: 2,
|
||||
state: Ticket::State.lookup(name: 'new'),
|
||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert(ticket1, 'ticket created')
|
||||
|
||||
article1 = Ticket::Article.create!(
|
||||
ticket_id: ticket1.id,
|
||||
from: 'some_customer_com-1@example.com',
|
||||
to: 'some_zammad_com-1@example.com',
|
||||
subject: 'com test 1',
|
||||
message_id: 'some@id_com_1',
|
||||
body: 'some message 123',
|
||||
internal: false,
|
||||
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
||||
type: Ticket::Article::Type.find_by(name: 'email'),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
||||
Observer::Transaction.commit
|
||||
Scheduler.worker(true)
|
||||
|
||||
ticket1.reload
|
||||
assert_equal('new', ticket1.state.name)
|
||||
|
||||
ticket1.with_lock do
|
||||
ticket1.update!(state_id: Ticket::State.find_by(name: 'closed').id)
|
||||
|
||||
article2 = Ticket::Article.create!(
|
||||
ticket_id: ticket1.id,
|
||||
from: 'some_zammad_com-1@example.com',
|
||||
to: 'some_customer_com-1@example.com',
|
||||
subject: 'com test 1',
|
||||
message_id: 'some@id_com_2',
|
||||
body: 'some message 123',
|
||||
internal: false,
|
||||
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
||||
type: Ticket::Article::Type.find_by(name: 'email'),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
end
|
||||
|
||||
Observer::Transaction.commit
|
||||
Scheduler.worker(true)
|
||||
|
||||
ticket1.reload
|
||||
assert_equal('closed', ticket1.state.name)
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue