2020-04-30 14:50:26 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ApplicationMailbox, type: :mailbox do
|
|
|
|
include ActionMailbox::TestHelper
|
|
|
|
|
|
|
|
describe 'route the inbound mail to appropriate mailbox' do
|
|
|
|
let(:welcome_mail) { create_inbound_email_from_fixture('welcome.eml') }
|
|
|
|
let(:reply_mail) { create_inbound_email_from_fixture('reply.eml') }
|
2020-09-21 17:14:22 +00:00
|
|
|
let(:support_mail) { create_inbound_email_from_fixture('support.eml') }
|
2020-04-30 14:50:26 +00:00
|
|
|
|
2020-09-21 17:14:22 +00:00
|
|
|
describe 'Default' do
|
|
|
|
it 'catchall mails route to Default Mailbox' do
|
|
|
|
dbl = double
|
|
|
|
expect(DefaultMailbox).to receive(:new).and_return(dbl)
|
|
|
|
expect(dbl).to receive(:perform_processing).and_return(true)
|
|
|
|
described_class.route welcome_mail
|
|
|
|
end
|
2020-04-30 14:50:26 +00:00
|
|
|
end
|
|
|
|
|
2020-09-21 17:14:22 +00:00
|
|
|
describe 'Reply' do
|
|
|
|
it 'routes reply emails to Reply Mailbox' do
|
|
|
|
dbl = double
|
|
|
|
expect(ReplyMailbox).to receive(:new).and_return(dbl)
|
|
|
|
expect(dbl).to receive(:perform_processing).and_return(true)
|
|
|
|
described_class.route reply_mail
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Support' do
|
|
|
|
let!(:channel_email) { create(:channel_email) }
|
|
|
|
|
2021-03-04 08:29:59 +00:00
|
|
|
it 'routes support emails to Support Mailbox when mail is to channel email' do
|
2020-09-21 17:14:22 +00:00
|
|
|
# this email is hardcoded in the support.eml, that's why we are updating this
|
2021-03-04 08:29:59 +00:00
|
|
|
channel_email.update(email: 'care@example.com')
|
|
|
|
dbl = double
|
|
|
|
expect(SupportMailbox).to receive(:new).and_return(dbl)
|
|
|
|
expect(dbl).to receive(:perform_processing).and_return(true)
|
|
|
|
described_class.route support_mail
|
2020-09-21 17:14:22 +00:00
|
|
|
end
|
|
|
|
|
2021-03-04 08:29:59 +00:00
|
|
|
it 'routes support emails to Support Mailbox when mail is to channel forward to email' do
|
|
|
|
# this email is hardcoded in the support.eml, that's why we are updating this
|
|
|
|
channel_email.update(forward_to_email: 'care@example.com')
|
2020-09-21 17:14:22 +00:00
|
|
|
dbl = double
|
|
|
|
expect(SupportMailbox).to receive(:new).and_return(dbl)
|
|
|
|
expect(dbl).to receive(:perform_processing).and_return(true)
|
|
|
|
described_class.route support_mail
|
|
|
|
end
|
2020-04-30 14:50:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|