Skip to content

Commit

Permalink
tested MAIL_SENDER more thoroughly
Browse files Browse the repository at this point in the history
  • Loading branch information
Janell-Huyck committed Oct 4, 2023
1 parent c5f4b2a commit ec05803
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions spec/mailers/publication_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,44 @@
expect(mail.from).to eq(['sender@example.com'])
end

context 'when MAIL_SENDER has name and email' do
before do
allow(ENV).to receive(:fetch).with('MAIL_SENDER').and_return('Sender Name <sender@example.com>')
end

let(:mail) { described_class.publication_submit(submitter, publication).deliver_now }

it 'uses the name and email in the from field' do
expect(mail.from).to eq(['sender@example.com'])
expect(mail[:from].display_names).to eq(['Sender Name'])
end
end

context 'when MAIL_SENDER is only an email' do
before do
allow(ENV).to receive(:fetch).with('MAIL_SENDER').and_return('sender@example.com')
end

let(:mail) { described_class.publication_submit(submitter, publication).deliver_now }

it 'uses just the email in the from field' do
expect(mail.from).to eq(['sender@example.com'])
end
end

context 'when MAIL_SENDER is empty' do
before do
allow(ENV).to receive(:fetch).with('MAIL_SENDER').and_return('')
end

let(:mail) { described_class.publication_submit(submitter, publication).deliver_now }

it 'raises an error' do
expect { mail }.to raise_error(ArgumentError, /SMTP From address may not be blank/)
end

end

it 'sends to the correct recipients' do
expect(mail.to).to eq(['submitter@example.com'])
expect(mail.bcc).to eq(['sender@example.com'])
Expand Down

0 comments on commit ec05803

Please sign in to comment.