mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-11 00:02:05 -05:00
107 lines
2.7 KiB
Ruby
107 lines
2.7 KiB
Ruby
|
# -*- encoding : utf-8 -*-
|
||
|
|
||
|
require 'spec_helper'
|
||
|
require 'email/receiver'
|
||
|
require 'jobs/scheduled/poll_mailbox'
|
||
|
require 'email/message_builder'
|
||
|
|
||
|
describe Jobs::PollMailbox do
|
||
|
|
||
|
describe "processing email" do
|
||
|
|
||
|
let!(:poller) { Jobs::PollMailbox.new }
|
||
|
let!(:receiver) { mock }
|
||
|
let!(:email) { mock }
|
||
|
|
||
|
before do
|
||
|
Email::Receiver.expects(:new).with(email).returns(receiver)
|
||
|
end
|
||
|
|
||
|
describe "all goes fine" do
|
||
|
|
||
|
it "email gets deleted" do
|
||
|
receiver.expects(:process)
|
||
|
email.expects(:delete)
|
||
|
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "raises Untrusted error" do
|
||
|
|
||
|
before do
|
||
|
receiver.expects(:process).raises(Email::Receiver::UserNotSufficientTrustLevelError)
|
||
|
email.expects(:delete)
|
||
|
|
||
|
Mail::Message.expects(:new).returns(email)
|
||
|
|
||
|
email.expects(:from)
|
||
|
email.expects(:body)
|
||
|
|
||
|
clientMessage = mock
|
||
|
senderMock = mock
|
||
|
RejectionMailer.expects(:send_trust_level).returns(clientMessage)
|
||
|
Email::Sender.expects(:new).with(
|
||
|
clientMessage, :email_reject_trust_level).returns(senderMock)
|
||
|
senderMock.expects(:send)
|
||
|
end
|
||
|
|
||
|
it "sends a reply and deletes the email" do
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "raises error" do
|
||
|
|
||
|
it "deletes email on ProcessingError" do
|
||
|
receiver.expects(:process).raises(Email::Receiver::ProcessingError)
|
||
|
email.expects(:delete)
|
||
|
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
|
||
|
it "deletes email on EmailUnparsableError" do
|
||
|
receiver.expects(:process).raises(Email::Receiver::EmailUnparsableError)
|
||
|
email.expects(:delete)
|
||
|
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
|
||
|
it "deletes email on EmptyEmailError" do
|
||
|
receiver.expects(:process).raises(Email::Receiver::EmptyEmailError)
|
||
|
email.expects(:delete)
|
||
|
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
|
||
|
it "deletes email on UserNotFoundError" do
|
||
|
receiver.expects(:process).raises(Email::Receiver::UserNotFoundError)
|
||
|
email.expects(:delete)
|
||
|
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
|
||
|
it "deletes email on EmailLogNotFound" do
|
||
|
receiver.expects(:process).raises(Email::Receiver::EmailLogNotFound)
|
||
|
email.expects(:delete)
|
||
|
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
|
||
|
|
||
|
it "informs admins on any other error" do
|
||
|
receiver.expects(:process).raises(TypeError)
|
||
|
email.expects(:delete)
|
||
|
GroupMessage.expects(:create) do |args|
|
||
|
args[0].should eq "admins"
|
||
|
args[1].shouled eq :email_error_notification
|
||
|
args[2].message_params.source.should eq email
|
||
|
args[2].message_params.error.should_be instance_of(TypeError)
|
||
|
end
|
||
|
|
||
|
poller.handle_mail(email)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|