DEV: do not fabricate a notification when fabricating a chat_mention (#20636)

This is just a little clean-up in tests. In the past, when creating a `chat_mention` 
record, we always created a related notification. Starting from fa543cda 
notifications and chat_mentions are fully decoupled from each other. So if we're 
testing just chat mentions there is no need to fabricate notifications for them.
This commit is contained in:
Andrei Prigorshnev 2023-03-10 18:32:33 +04:00 committed by GitHub
parent 3e8d349465
commit 7df40fc905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 47 deletions

View File

@ -40,10 +40,7 @@ describe Chat::ChatMailer do
end end
describe "for chat mentions" do describe "for chat mentions" do
fab!(:notification) { Fabricate(:notification) } fab!(:mention) { Fabricate(:chat_mention, user: user_1, chat_message: chat_message) }
fab!(:mention) do
Fabricate(:chat_mention, user: user_1, chat_message: chat_message, notification: notification)
end
it "skips users without chat access" do it "skips users without chat access" do
chatters_group.remove(user_1) chatters_group.remove(user_1)
@ -154,13 +151,7 @@ describe Chat::ChatMailer do
last_unread_mention_when_emailed_id: chat_message.id, last_unread_mention_when_emailed_id: chat_message.id,
) )
unread_message = Fabricate(:chat_message, chat_channel: chat_channel, user: sender) unread_message = Fabricate(:chat_message, chat_channel: chat_channel, user: sender)
notification = Fabricate(:notification) Fabricate(:chat_mention, user: user_1, chat_message: unread_message)
Fabricate(
:chat_mention,
user: user_1,
chat_message: unread_message,
notification: notification,
)
described_class.send_unread_mentions_summary described_class.send_unread_mentions_summary
@ -179,7 +170,6 @@ describe Chat::ChatMailer do
it "doesn't mix mentions from other users" do it "doesn't mix mentions from other users" do
mention.destroy! mention.destroy!
user_2 = Fabricate(:user, groups: [chatters_group], last_seen_at: 20.minutes.ago) user_2 = Fabricate(:user, groups: [chatters_group], last_seen_at: 20.minutes.ago)
user_2_membership =
Fabricate( Fabricate(
:user_chat_channel_membership, :user_chat_channel_membership,
user: user_2, user: user_2,
@ -187,8 +177,7 @@ describe Chat::ChatMailer do
last_read_message_id: nil, last_read_message_id: nil,
) )
new_message = Fabricate(:chat_message, chat_channel: chat_channel, user: sender) new_message = Fabricate(:chat_message, chat_channel: chat_channel, user: sender)
notification = Fabricate(:notification) Fabricate(:chat_mention, user: user_2, chat_message: new_message)
Fabricate(:chat_mention, user: user_2, chat_message: new_message, notification: notification)
described_class.send_unread_mentions_summary described_class.send_unread_mentions_summary
@ -227,13 +216,7 @@ describe Chat::ChatMailer do
) )
another_channel_message = Fabricate(:chat_message, chat_channel: chat_channel, user: sender) another_channel_message = Fabricate(:chat_message, chat_channel: chat_channel, user: sender)
notification = Fabricate(:notification) Fabricate(:chat_mention, user: user_1, chat_message: another_channel_message)
Fabricate(
:chat_mention,
user: user_1,
chat_message: another_channel_message,
notification: notification,
)
expect { described_class.send_unread_mentions_summary }.not_to change( expect { described_class.send_unread_mentions_summary }.not_to change(
Jobs::UserEmail.jobs, Jobs::UserEmail.jobs,
@ -245,13 +228,7 @@ describe Chat::ChatMailer do
another_channel = Fabricate(:category_channel) another_channel = Fabricate(:category_channel)
another_channel_message = another_channel_message =
Fabricate(:chat_message, chat_channel: another_channel, user: sender) Fabricate(:chat_message, chat_channel: another_channel, user: sender)
notification = Fabricate(:notification) Fabricate(:chat_mention, user: user_1, chat_message: another_channel_message)
Fabricate(
:chat_mention,
user: user_1,
chat_message: another_channel_message,
notification: notification,
)
another_channel_membership = another_channel_membership =
Fabricate( Fabricate(
:user_chat_channel_membership, :user_chat_channel_membership,
@ -281,15 +258,14 @@ describe Chat::ChatMailer do
end end
it "only queues the job once when the user has mentions and private messages" do it "only queues the job once when the user has mentions and private messages" do
notification = Fabricate(:notification) Fabricate(:chat_mention, user: user_1, chat_message: chat_message)
Fabricate(:chat_mention, user: user_1, chat_message: chat_message, notification: notification)
described_class.send_unread_mentions_summary described_class.send_unread_mentions_summary
assert_only_queued_once assert_only_queued_once
end end
it "Doesn't mix or update mentions from other users when joining tables" do it "doesn't mix or update mentions from other users when joining tables" do
user_2 = Fabricate(:user, groups: [chatters_group], last_seen_at: 20.minutes.ago) user_2 = Fabricate(:user, groups: [chatters_group], last_seen_at: 20.minutes.ago)
user_2_membership = user_2_membership =
Fabricate( Fabricate(
@ -298,8 +274,7 @@ describe Chat::ChatMailer do
chat_channel: chat_channel, chat_channel: chat_channel,
last_read_message_id: chat_message.id, last_read_message_id: chat_message.id,
) )
notification = Fabricate(:notification) Fabricate(:chat_mention, user: user_2, chat_message: chat_message)
Fabricate(:chat_mention, user: user_2, chat_message: chat_message, notification: notification)
described_class.send_unread_mentions_summary described_class.send_unread_mentions_summary

View File

@ -109,14 +109,7 @@ describe Chat::MessageMover do
it "updates references for reactions, uploads, revisions, mentions, etc." do it "updates references for reactions, uploads, revisions, mentions, etc." do
reaction = Fabricate(:chat_message_reaction, chat_message: message1) reaction = Fabricate(:chat_message_reaction, chat_message: message1)
upload = Fabricate(:upload_reference, target: message1) upload = Fabricate(:upload_reference, target: message1)
notification = Fabricate(:notification) mention = Fabricate(:chat_mention, chat_message: message2, user: acting_user)
mention =
Fabricate(
:chat_mention,
chat_message: message2,
user: acting_user,
notification: notification,
)
revision = Fabricate(:chat_message_revision, chat_message: message3) revision = Fabricate(:chat_message_revision, chat_message: message3)
webhook_event = Fabricate(:chat_webhook_event, chat_message: message3) webhook_event = Fabricate(:chat_webhook_event, chat_message: message3)
move! move!

View File

@ -471,6 +471,7 @@ describe ChatMessage do
message_1.destroy! message_1.destroy!
expect { mention_1.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { mention_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
end end
it "destroys chat_webhook_event" do it "destroys chat_webhook_event" do