2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-06-03 16:12:24 -04:00
|
|
|
|
|
|
|
describe Admin::EmailController do
|
|
|
|
|
|
|
|
it "is a subclass of AdminController" do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(Admin::EmailController < Admin::AdminController).to eq(true)
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:user) { log_in(:admin) }
|
|
|
|
|
|
|
|
context '.index' do
|
|
|
|
before do
|
2017-08-31 00:06:56 -04:00
|
|
|
subject
|
|
|
|
.expects(:action_mailer_settings)
|
|
|
|
.returns(
|
|
|
|
username: 'username',
|
|
|
|
password: 'secret'
|
|
|
|
)
|
|
|
|
|
|
|
|
get :index, format: :json
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
2013-06-11 19:00:13 -04:00
|
|
|
it 'does not include the password in the response' do
|
|
|
|
mail_settings = JSON.parse(response.body)['settings']
|
|
|
|
|
|
|
|
expect(
|
|
|
|
mail_settings.select { |setting| setting['name'] == 'password' }
|
|
|
|
).to be_empty
|
|
|
|
end
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
2014-02-14 18:50:08 -05:00
|
|
|
context '.sent' do
|
2013-06-03 16:12:24 -04:00
|
|
|
before do
|
2017-08-31 00:06:56 -04:00
|
|
|
get :sent, format: :json
|
2014-02-14 18:50:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { response }
|
2015-01-09 12:04:02 -05:00
|
|
|
it { is_expected.to be_success }
|
2014-02-14 18:50:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.skipped' do
|
|
|
|
before do
|
2017-08-31 00:06:56 -04:00
|
|
|
get :skipped, format: :json
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { response }
|
2015-01-09 12:04:02 -05:00
|
|
|
it { is_expected.to be_success }
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.test' do
|
|
|
|
it 'raises an error without the email parameter' do
|
2017-08-31 00:06:56 -04:00
|
|
|
expect do
|
|
|
|
post :test, format: :json
|
|
|
|
end.to raise_error(ActionController::ParameterMissing)
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an email address' do
|
|
|
|
it 'enqueues a test email job' do
|
2014-01-09 16:31:26 -05:00
|
|
|
job_mock = mock
|
|
|
|
Jobs::TestEmail.expects(:new).returns(job_mock)
|
|
|
|
job_mock.expects(:execute).with(to_address: 'eviltrout@test.domain')
|
2017-08-31 00:06:56 -04:00
|
|
|
post :test, params: { email_address: 'eviltrout@test.domain' }, format: :json
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '.preview_digest' do
|
|
|
|
it 'raises an error without the last_seen_at parameter' do
|
2017-08-31 00:06:56 -04:00
|
|
|
expect do
|
|
|
|
get :preview_digest, format: :json
|
|
|
|
end.to raise_error(ActionController::ParameterMissing)
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "previews the digest" do
|
2017-08-31 00:06:56 -04:00
|
|
|
get :preview_digest, params: {
|
|
|
|
last_seen_at: 1.week.ago, username: user.username
|
|
|
|
}, format: :json
|
|
|
|
|
2013-06-03 16:12:24 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-24 00:06:28 -04:00
|
|
|
context '#handle_mail' do
|
|
|
|
before do
|
|
|
|
log_in_user(Fabricate(:admin))
|
|
|
|
SiteSetting.queue_jobs = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should enqueue the right job' do
|
2017-08-31 00:06:56 -04:00
|
|
|
expect { post :handle_mail, params: { email: email('cc') }, format: :json }
|
2017-04-24 00:06:28 -04:00
|
|
|
.to change { Jobs::ProcessEmail.jobs.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-04 14:04:26 -04:00
|
|
|
context '.rejected' do
|
|
|
|
it 'should provide a string for a blank error' do
|
|
|
|
Fabricate(:incoming_email, error: "")
|
2017-08-31 00:06:56 -04:00
|
|
|
get :rejected, format: :json
|
2017-08-04 14:04:26 -04:00
|
|
|
rejected = JSON.parse(response.body)
|
|
|
|
expect(rejected.first['error']).to eq(I18n.t("emails.incoming.unrecognized_error"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '.incoming' do
|
|
|
|
it 'should provide a string for a blank error' do
|
|
|
|
incoming_email = Fabricate(:incoming_email, error: "")
|
2017-08-31 00:06:56 -04:00
|
|
|
get :incoming, params: { id: incoming_email.id }, format: :json
|
2017-08-04 14:04:26 -04:00
|
|
|
incoming = JSON.parse(response.body)
|
|
|
|
expect(incoming['error']).to eq(I18n.t("emails.incoming.unrecognized_error"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|