|
3 | 3 | require 'rails_helper' |
4 | 4 |
|
5 | 5 | module BetterTogether |
6 | | - RSpec.describe ConversationMailer, type: :mailer do |
7 | | - # describe 'new_message_notification' do |
8 | | - # let(:mail) { ConversationMailer.new_message_notification } |
| 6 | + RSpec.describe ConversationMailer, type: :mailer do # rubocop:todo Metrics/BlockLength |
| 7 | + describe 'new_message_notification' do # rubocop:todo Metrics/BlockLength |
| 8 | + let!(:host_platform) { create(:platform, :host) } |
| 9 | + let(:sender) { create(:user) } |
| 10 | + let(:recipient) { create(:user) } |
| 11 | + let(:conversation) { create(:conversation, creator: sender.person) } |
| 12 | + let(:message) { create(:message, conversation: conversation, sender: sender.person) } |
9 | 13 |
|
10 | | - # it 'renders the headers' do |
11 | | - # expect(mail.subject).to eq('New message notification') |
12 | | - # expect(mail.to).to eq(['[email protected]']) |
13 | | - # expect(mail.from).to eq(['[email protected]']) |
14 | | - # end |
| 14 | + let(:mail) do |
| 15 | + ConversationMailer.with(message: message, recipient: recipient.person) |
| 16 | + .new_message_notification |
| 17 | + end |
15 | 18 |
|
16 | | - # it 'renders the body' do |
17 | | - # expect(mail.body.encoded).to match('Hi') |
18 | | - # end |
19 | | - # end |
| 19 | + it 'renders the headers' do |
| 20 | + expect(mail.subject).to eq("[#{host_platform.name}] New message in conversation \"#{conversation.title}\"") |
| 21 | + expect(mail.to).to eq([recipient.email]) |
| 22 | + expect(mail.from).to eq(['[email protected]']) |
| 23 | + end |
| 24 | + |
| 25 | + it 'renders the body' do |
| 26 | + expect(mail.body.encoded).to have_content("Hello #{recipient.person.name}") |
| 27 | + expect(mail.body.encoded).to have_content("#{sender.person.name}:") |
| 28 | + expect(mail.body.encoded).to have_content(message.content.to_plain_text) |
| 29 | + end |
| 30 | + |
| 31 | + it 'sends a message notification email' do |
| 32 | + expect { mail.deliver_now } |
| 33 | + .to change { ActionMailer::Base.deliveries.count }.by(1) |
| 34 | + end |
| 35 | + |
| 36 | + it 'sends the message notification to the correct email address' do |
| 37 | + mail.deliver_now |
| 38 | + expect(ActionMailer::Base.deliveries.last.to).to include(recipient.email) |
| 39 | + end |
| 40 | + end |
20 | 41 | end |
21 | 42 | end |
0 commit comments