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