DEV: do not fabricate a Notification when fabricating a ChatMention (#20450)

Initially, the chat_mention db table was created to support notifications. So when creating 
a `chat_mention` record we were always creating a related `notification` record. So did the
ChatMention fabricator. 

Now we want to use the chat_mention db table in other scenarios. So we started decoupling 
mentions from notification in 75b81b68.

This removes fabrication of Notifications from the ChatMention fabricator. We need to be able 
to fabricate a ChatMention without a Notification.
This commit is contained in:
Andrei Prigorshnev
2023-02-27 14:41:28 +04:00
committed by GitHub
parent e82b8c2b06
commit 69c7df2e56
5 changed files with 96 additions and 55 deletions

View File

@ -163,7 +163,15 @@ describe UserNotifications do
describe "email subject" do
context "with regular mentions" do
before { Fabricate(:chat_mention, user: user, chat_message: chat_message) }
before do
notification = Fabricate(:notification)
Fabricate(
:chat_mention,
user: user,
chat_message: chat_message,
notification: notification,
)
end
it "includes the sender username in the subject" do
expected_subject =
@ -194,7 +202,13 @@ describe UserNotifications do
user: user,
last_read_message_id: another_chat_message.id - 2,
)
Fabricate(:chat_mention, user: user, chat_message: another_chat_message)
notification = Fabricate(:notification)
Fabricate(
:chat_mention,
user: user,
chat_message: another_chat_message,
notification: notification,
)
email = described_class.chat_summary(user, {})
@ -227,7 +241,13 @@ describe UserNotifications do
user: user,
last_read_message_id: another_chat_message.id - 2,
)
Fabricate(:chat_mention, user: user, chat_message: another_chat_message)
notification = Fabricate(:notification)
Fabricate(
:chat_mention,
user: user,
chat_message: another_chat_message,
notification: notification,
)
end
expected_subject =
@ -253,7 +273,13 @@ describe UserNotifications do
target_users: [sender, user],
)
Fabricate(:chat_message, user: sender, chat_channel: channel)
Fabricate(:chat_mention, user: user, chat_message: chat_message)
notification = Fabricate(:notification)
Fabricate(
:chat_mention,
user: user,
chat_message: chat_message,
notification: notification,
)
end
it "always includes the DM second" do
@ -273,7 +299,15 @@ describe UserNotifications do
end
describe "When there are mentions" do
before { Fabricate(:chat_mention, user: user, chat_message: chat_message) }
before do
notification = Fabricate(:notification)
Fabricate(
:chat_mention,
user: user,
chat_message: chat_message,
notification: notification,
)
end
describe "selecting mentions" do
it "doesn't return an email if the user can't see chat" do
@ -377,7 +411,13 @@ describe UserNotifications do
)
new_message = Fabricate(:chat_message, user: sender, chat_channel: channel)
Fabricate(:chat_mention, user: user, chat_message: new_message)
notification = Fabricate(:notification)
Fabricate(
:chat_mention,
user: user,
chat_message: new_message,
notification: notification,
)
email = described_class.chat_summary(user, {})
@ -478,7 +518,8 @@ describe UserNotifications do
it "includes a view more link when there are more than two mentions" do
2.times do
msg = Fabricate(:chat_message, user: sender, chat_channel: channel)
Fabricate(:chat_mention, user: user, chat_message: msg)
notification = Fabricate(:notification)
Fabricate(:chat_mention, user: user, chat_message: msg, notification: notification)
end
email = described_class.chat_summary(user, {})
@ -499,7 +540,13 @@ describe UserNotifications do
new_message =
Fabricate(:chat_message, user: sender, chat_channel: channel, cooked: "New message")
Fabricate(:chat_mention, user: user, chat_message: new_message)
notification = Fabricate(:notification)
Fabricate(
:chat_mention,
user: user,
chat_message: new_message,
notification: notification,
)
email = described_class.chat_summary(user, {})
body = email.html_part.body.to_s