forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: Migrate email_process_out_of_office_test to RSpec
- Loading branch information
1 parent
3b1e51c
commit 7a79f97
Showing
3 changed files
with
147 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -540,5 +540,55 @@ | |
end | ||
end | ||
end | ||
|
||
context 'for “out-of-office” notifications (a.k.a. auto-response messages)' do | ||
let(:raw_mail) { <<~RAW.chomp } | ||
From: [email protected] | ||
To: [email protected] | ||
Subject: #{subject_line} | ||
Some Text | ||
RAW | ||
let(:subject_line) { 'Lorem ipsum dolor' } | ||
|
||
it 'applies the OutOfOfficeCheck filter to given message' do | ||
expect(Channel::Filter::OutOfOfficeCheck) | ||
.to receive(:run) | ||
.with(kind_of(Hash), hash_including(subject: subject_line)) | ||
|
||
described_class.new.process({}, raw_mail) | ||
end | ||
|
||
context 'on an existing, closed ticket' do | ||
let(:ticket) { create(:ticket, state_name: 'closed') } | ||
let(:subject_line) { ticket.subject_build('Lorem ipsum dolor') } | ||
|
||
context 'when OutOfOfficeCheck filter applies x-zammad-out-of-office: false' do | ||
before do | ||
allow(Channel::Filter::OutOfOfficeCheck) | ||
.to receive(:run) { |_, mail_hash| mail_hash[:'x-zammad-out-of-office'] = false } | ||
end | ||
|
||
it 're-opens a closed ticket' do | ||
expect { described_class.new.process({}, raw_mail) } | ||
.to not_change { Ticket.count } | ||
.and change { ticket.reload.state.name }.to('open') | ||
end | ||
end | ||
|
||
context 'when OutOfOfficeCheck filter applies x-zammad-out-of-office: true' do | ||
before do | ||
allow(Channel::Filter::OutOfOfficeCheck) | ||
.to receive(:run) { |_, mail_hash| mail_hash[:'x-zammad-out-of-office'] = true } | ||
end | ||
|
||
it 'does not re-open a closed ticket' do | ||
expect { described_class.new.process({}, raw_mail) } | ||
.to not_change { Ticket.count } | ||
.and not_change { ticket.reload.state.name } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Channel::Filter::OutOfOfficeCheck do | ||
describe '.run' do | ||
let(:mail_hash) { Channel::EmailParser.new.parse(<<~RAW.chomp) } | ||
From: [email protected] | ||
To: [email protected] | ||
Subject: #{subject_line} | ||
#{client_headers} | ||
Some Text | ||
RAW | ||
|
||
let(:subject_line) { 'Lorem ipsum dolor' } | ||
|
||
shared_examples 'regular message' do | ||
it 'sets x-zammad-out-of-office header to false' do | ||
expect { described_class.run({}, mail_hash) } | ||
.to change { mail_hash[:'x-zammad-out-of-office'] }.to(false) | ||
end | ||
end | ||
|
||
shared_examples 'auto-response' do | ||
it 'sets x-zammad-out-of-office header to true' do | ||
expect { described_class.run({}, mail_hash) } | ||
.to change { mail_hash[:'x-zammad-out-of-office'] }.to(true) | ||
end | ||
end | ||
|
||
context 'for regular messages' do | ||
context 'with MS/Exchange-style headers' do | ||
let(:client_headers) { 'X-MS-Exchange-Inbox-Rules-Loop: [email protected]' } | ||
|
||
include_examples 'regular message' | ||
end | ||
|
||
context 'with Zimbra-style headers' do | ||
let(:client_headers) { 'X-Mailer: Zimbra 7.1.3_GA_3346' } | ||
|
||
include_examples 'regular message' | ||
end | ||
|
||
context 'with no additional headers (Cloud- & Gmail-style)' do | ||
let(:client_headers) { '' } | ||
|
||
include_examples 'regular message' | ||
end | ||
end | ||
|
||
context 'for auto-response messages' do | ||
context 'with MS/Exchange-style headers' do | ||
let(:client_headers) { <<~HEAD.chomp } | ||
X-MS-Has-Attach: | ||
X-Auto-Response-Suppress: All | ||
X-MS-Exchange-Inbox-Rules-Loop: [email protected] | ||
X-MS-TNEF-Correlator: | ||
x-olx-disclaimer: Done | ||
x-tm-as-product-ver: SMEX-11.0.0.4179-8.000.1202-21706.006 | ||
x-tm-as-result: No--39.689200-0.000000-31 | ||
x-tm-as-user-approved-sender: Yes | ||
x-tm-as-user-blocked-sender: No | ||
HEAD | ||
|
||
include_examples 'auto-response' | ||
end | ||
|
||
context 'with Zimbra-style headers' do | ||
let(:client_headers) { <<~HEAD.chomp } | ||
Auto-Submitted: auto-replied (zimbra; vacation) | ||
Precedence: bulk | ||
X-Mailer: Zimbra 7.1.3_GA_3346 | ||
HEAD | ||
|
||
include_examples 'auto-response' | ||
end | ||
|
||
context 'with Cloud-style headers' do | ||
let(:client_headers) { <<~HEAD.chomp } | ||
Auto-submitted: auto-replied; owner-email="[email protected]" | ||
HEAD | ||
|
||
include_examples 'auto-response' | ||
end | ||
|
||
context 'with Gmail-style headers' do | ||
let(:subject_line) { 'vacation: Lorem ipsum dolor' } | ||
let(:client_headers) { <<~HEAD.chomp } | ||
Precedence: bulk | ||
X-Autoreply: yes | ||
Auto-Submitted: auto-replied | ||
HEAD | ||
|
||
include_examples 'auto-response' | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.