diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb index 26469db3d..4b8963f8f 100644 --- a/spec/models/channel/email_parser_spec.rb +++ b/spec/models/channel/email_parser_spec.rb @@ -91,12 +91,62 @@ RSpec.describe Channel::EmailParser, type: :model do let(:ticket) { create(:ticket) } context 'when email subject contains ticket reference' do - let(:raw_mail) { File.read(mail_file).sub(/(?<=^Subject: ).*$/, ticket_ref) } + let(:raw_mail) { File.read(mail_file).sub(/(?<=^Subject: ).*$/, ticket_ref) } it 'adds message to ticket' do expect { described_class.new.process({}, raw_mail) } .to change { ticket.articles.length } 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 context 'when configured to search body' do diff --git a/test/unit/email_process_follow_up_possible_test.rb b/test/unit/email_process_follow_up_possible_test.rb deleted file mode 100644 index ed05bf634..000000000 --- a/test/unit/email_process_follow_up_possible_test.rb +++ /dev/null @@ -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