2015-08-20 14:47:09 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
2017-08-02 11:13:27 -04:00
|
|
|
describe EmailReceiverWorker, :mailer do
|
2015-08-20 15:34:45 -04:00
|
|
|
let(:raw_message) { fixture_file('emails/valid_reply.eml') }
|
2015-08-20 14:47:09 -04:00
|
|
|
|
|
|
|
context "when reply by email is enabled" do
|
|
|
|
before do
|
2015-09-21 03:46:47 -04:00
|
|
|
allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(true)
|
2015-08-20 14:47:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "calls the email receiver" do
|
|
|
|
expect(Gitlab::Email::Receiver).to receive(:new).with(raw_message).and_call_original
|
|
|
|
expect_any_instance_of(Gitlab::Email::Receiver).to receive(:execute)
|
|
|
|
|
|
|
|
described_class.new.perform(raw_message)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when an error occurs" do
|
|
|
|
before do
|
2017-08-02 11:13:27 -04:00
|
|
|
allow_any_instance_of(Gitlab::Email::Receiver).to receive(:execute).and_raise(error)
|
2015-08-20 14:47:09 -04:00
|
|
|
end
|
|
|
|
|
2017-08-02 11:13:27 -04:00
|
|
|
context 'when the error is Gitlab::Email::EmptyEmailError' do
|
|
|
|
let(:error) { Gitlab::Email::EmptyEmailError }
|
|
|
|
|
|
|
|
it 'sends out a rejection email' do
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
described_class.new.perform(raw_message)
|
|
|
|
end
|
2015-11-30 09:12:31 -05:00
|
|
|
|
|
|
|
email = ActionMailer::Base.deliveries.last
|
|
|
|
expect(email).not_to be_nil
|
|
|
|
expect(email.to).to eq(["jake@adventuretime.ooo"])
|
|
|
|
expect(email.subject).to include("Rejected")
|
|
|
|
end
|
2015-08-20 14:47:09 -04:00
|
|
|
end
|
2017-08-02 11:13:27 -04:00
|
|
|
|
|
|
|
context 'when the error is Gitlab::Email::AutoGeneratedEmailError' do
|
|
|
|
let(:error) { Gitlab::Email::AutoGeneratedEmailError }
|
|
|
|
|
|
|
|
it 'does not send out any rejection email' do
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
described_class.new.perform(raw_message)
|
|
|
|
end
|
|
|
|
|
|
|
|
should_not_email_anyone
|
|
|
|
end
|
|
|
|
end
|
2015-08-20 14:47:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when reply by email is disabled" do
|
|
|
|
before do
|
2015-09-21 03:46:47 -04:00
|
|
|
allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(false)
|
2015-08-20 14:47:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't call the email receiver" do
|
|
|
|
expect(Gitlab::Email::Receiver).not_to receive(:new)
|
|
|
|
|
|
|
|
described_class.new.perform(raw_message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|