Refactoring: Migrate email_process_follow_up_possible_test to RSpec
This commit is contained in:
parent
d3bbdd3b00
commit
b65a84f95e
2 changed files with 51 additions and 72 deletions
|
@ -97,6 +97,56 @@ RSpec.describe Channel::EmailParser, type: :model do
|
||||||
expect { described_class.new.process({}, raw_mail) }
|
expect { described_class.new.process({}, raw_mail) }
|
||||||
.to change { ticket.articles.length }
|
.to change { ticket.articles.length }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'and ticket is closed' do
|
||||||
|
before { ticket.update(state: Ticket::State.find_by(name: 'closed')) }
|
||||||
|
|
||||||
|
it 'adds message to ticket' do
|
||||||
|
expect { described_class.new.process({}, raw_mail) }
|
||||||
|
.to change { ticket.articles.length }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'but ticket group’s #follow_up_possible attribute is "new_ticket"' do
|
||||||
|
before { ticket.group.update(follow_up_possible: 'new_ticket') }
|
||||||
|
|
||||||
|
context 'and ticket is open' do
|
||||||
|
it 'still adds message to ticket' do
|
||||||
|
expect { described_class.new.process({}, raw_mail) }
|
||||||
|
.to change { ticket.articles.length }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and ticket is closed' do
|
||||||
|
before { ticket.update(state: Ticket::State.find_by(name: 'closed')) }
|
||||||
|
|
||||||
|
it 'creates a new ticket' do
|
||||||
|
expect { described_class.new.process({}, raw_mail) }
|
||||||
|
.to change { Ticket.count }.by(1)
|
||||||
|
.and not_change { ticket.articles.length }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and ticket is merged' do
|
||||||
|
before { ticket.update(state: Ticket::State.find_by(name: 'merged')) }
|
||||||
|
|
||||||
|
it 'creates a new ticket' do
|
||||||
|
expect { described_class.new.process({}, raw_mail) }
|
||||||
|
.to change { Ticket.count }.by(1)
|
||||||
|
.and not_change { ticket.articles.length }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and ticket is removed' do
|
||||||
|
before { ticket.update(state: Ticket::State.find_by(name: 'removed')) }
|
||||||
|
|
||||||
|
it 'creates a new ticket' do
|
||||||
|
expect { described_class.new.process({}, raw_mail) }
|
||||||
|
.to change { Ticket.count }.by(1)
|
||||||
|
.and not_change { ticket.articles.length }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when configured to search body' do
|
context 'when configured to search body' do
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
require 'test_helper'
|
|
||||||
|
|
||||||
class EmailProcessFollowUpPossibleTest < ActiveSupport::TestCase
|
|
||||||
|
|
||||||
test 'process with follow up possible check' do
|
|
||||||
|
|
||||||
users_group = Group.lookup(name: 'Users')
|
|
||||||
|
|
||||||
ticket = Ticket.create(
|
|
||||||
title: 'follow up check',
|
|
||||||
group: users_group,
|
|
||||||
customer_id: 2,
|
|
||||||
state: Ticket::State.lookup(name: 'new'),
|
|
||||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
||||||
updated_by_id: 1,
|
|
||||||
created_by_id: 1,
|
|
||||||
)
|
|
||||||
article = Ticket::Article.create(
|
|
||||||
ticket_id: ticket.id,
|
|
||||||
from: 'some_sender@example.com',
|
|
||||||
to: 'some_recipient@example.com',
|
|
||||||
subject: 'follow up check',
|
|
||||||
message_id: '<20150830145601.30.608882@edenhofer.zammad.com>',
|
|
||||||
body: 'some message article',
|
|
||||||
internal: false,
|
|
||||||
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
|
|
||||||
type: Ticket::Article::Type.lookup(name: 'email'),
|
|
||||||
updated_by_id: 1,
|
|
||||||
created_by_id: 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
follow_up_raw = "From: me@example.com
|
|
||||||
To: customer@example.com
|
|
||||||
Subject: #{ticket.subject_build('some new subject')}
|
|
||||||
|
|
||||||
Some Text"
|
|
||||||
|
|
||||||
users_group.update!('follow_up_possible' => 'new_ticket')
|
|
||||||
|
|
||||||
travel 1.second
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, follow_up_raw)
|
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
|
||||||
assert_equal('follow up check', ticket_p.title)
|
|
||||||
assert_match('some new subject', article_p.subject)
|
|
||||||
|
|
||||||
# close ticket
|
|
||||||
ticket.state = Ticket::State.find_by(name: 'closed')
|
|
||||||
ticket.save!
|
|
||||||
|
|
||||||
follow_up_raw = "From: me@example.com
|
|
||||||
To: customer@example.com
|
|
||||||
Subject: #{ticket.subject_build('some new subject2')}
|
|
||||||
|
|
||||||
Some Text"
|
|
||||||
|
|
||||||
travel 1.second
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, follow_up_raw)
|
|
||||||
assert_not_equal(ticket.id, ticket_p.id)
|
|
||||||
assert_equal('some new subject2', ticket_p.title)
|
|
||||||
assert_equal('some new subject2', article_p.subject)
|
|
||||||
|
|
||||||
users_group.update!('follow_up_possible' => 'yes')
|
|
||||||
|
|
||||||
travel 1.second
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, follow_up_raw)
|
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
|
||||||
assert_equal('follow up check', ticket_p.title)
|
|
||||||
assert_match('some new subject', article_p.subject)
|
|
||||||
travel_back
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in a new issue