DEV: Add SMTP group ID to EmailLog (#13381)

Adds a new `smtp_group_id` column to `EmailLog` which is filled in if the mail `from_address` matches a group's `email_username`. This is for easier debugging, so we know which emails have been sent via group SMTP.
This commit is contained in:
Martin Brennan
2021-06-15 11:29:46 +10:00
committed by GitHub
parent 5f8f139ac9
commit 7fca7fb7ff
6 changed files with 73 additions and 19 deletions

View File

@@ -337,6 +337,36 @@ describe Email::Sender do
expect(email_log.to_address).to eq('eviltrout@test.domain')
expect(email_log.user_id).to be_blank
end
context 'when the email is sent using group SMTP credentials' do
let(:reply) { Fabricate(:post, topic: post.topic, reply_to_user: post.user, reply_to_post_number: post.post_number) }
let(:notification) { Fabricate(:posted_notification, user: post.user, post: reply) }
let(:message) do
UserNotifications.user_private_message(
post.user,
post: reply,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
end
let(:group) { Fabricate(:smtp_group) }
before do
SiteSetting.enable_smtp = true
end
it 'adds the group id to the email log' do
TopicAllowedGroup.create(topic: post.topic, group: group)
email_sender.send
expect(email_log).to be_present
expect(email_log.email_type).to eq('valid_type')
expect(email_log.to_address).to eq(post.user.email)
expect(email_log.user_id).to be_blank
expect(email_log.smtp_group_id).to eq(group.id)
end
end
end
context "email log with a post id and topic id" do