diff options
Diffstat (limited to 'spec/workers/email_receiver_worker_spec.rb')
-rw-r--r-- | spec/workers/email_receiver_worker_spec.rb | 78 |
1 files changed, 18 insertions, 60 deletions
diff --git a/spec/workers/email_receiver_worker_spec.rb b/spec/workers/email_receiver_worker_spec.rb index 83720ee132b..dba535654a1 100644 --- a/spec/workers/email_receiver_worker_spec.rb +++ b/spec/workers/email_receiver_worker_spec.rb @@ -21,87 +21,45 @@ RSpec.describe EmailReceiverWorker, :mailer do context "when an error occurs" do before do allow_any_instance_of(Gitlab::Email::Receiver).to receive(:execute).and_raise(error) - expect(Sidekiq.logger).to receive(:error).with(hash_including('exception.class' => error.class.name)).and_call_original end - context 'when the error is Gitlab::Email::EmptyEmailError' do + context 'when error is a processing error' do let(:error) { Gitlab::Email::EmptyEmailError.new } - it 'sends out a rejection email' do - perform_enqueued_jobs do - described_class.new.perform(raw_message) + it 'triggers email failure handler' do + expect(Gitlab::Email::FailureHandler).to receive(:handle) do |receiver, received_error| + expect(receiver).to be_a(Gitlab::Email::Receiver) + expect(receiver.mail.encoded).to eql(Mail::Message.new(raw_message).encoded) + expect(received_error).to be(error) end - 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 - - it 'strips out the body before passing to EmailRejectionMailer' do - mail = Mail.new(raw_message) - mail.body = nil - - expect(EmailRejectionMailer).to receive(:rejection).with(anything, mail.encoded, anything).and_call_original - described_class.new.perform(raw_message) end - end - - context 'when the error is Gitlab::Email::AutoGeneratedEmailError' do - let(:error) { Gitlab::Email::AutoGeneratedEmailError.new } - - 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 - context 'when the error is Gitlab::Email::InvalidAttachment' do - let(:error) { Gitlab::Email::InvalidAttachment.new("Could not deal with that") } + it 'logs the error' do + expect(Sidekiq.logger).to receive(:error).with(hash_including('exception.class' => error.class.name)).and_call_original - it 'reports the error to the sender' do - perform_enqueued_jobs do - described_class.new.perform(raw_message) - end - - email = ActionMailer::Base.deliveries.last - expect(email).not_to be_nil - expect(email.to).to eq(["jake@adventuretime.ooo"]) - expect(email.body.parts.last.to_s).to include("Could not deal with that") + described_class.new.perform(raw_message) end end - context 'when the error is ActiveRecord::StatementTimeout' do + context 'when error is not a processing error' do let(:error) { ActiveRecord::StatementTimeout.new("Statement timeout") } - it 'does not report the error to the sender' do - expect(Gitlab::ErrorTracking).to receive(:track_exception).with(error).and_call_original - - perform_enqueued_jobs do - described_class.new.perform(raw_message) + it 'triggers email failure handler' do + expect(Gitlab::Email::FailureHandler).to receive(:handle) do |receiver, received_error| + expect(receiver).to be_a(Gitlab::Email::Receiver) + expect(receiver.mail.encoded).to eql(Mail::Message.new(raw_message).encoded) + expect(received_error).to be(error) end - email = ActionMailer::Base.deliveries.last - expect(email).to be_nil + described_class.new.perform(raw_message) end - end - - context 'when the error is RateLimitedService::RateLimitedError' do - let(:error) { RateLimitedService::RateLimitedError.new(key: :issues_create, rate_limiter: Gitlab::ApplicationRateLimiter) } - it 'does not report the error to the sender' do + it 'reports the error' do expect(Gitlab::ErrorTracking).to receive(:track_exception).with(error).and_call_original - perform_enqueued_jobs do - described_class.new.perform(raw_message) - end - - email = ActionMailer::Base.deliveries.last - expect(email).to be_nil + described_class.new.perform(raw_message) end end end |