DEV: group tests related to mentions (#22017)

This commit is contained in:
Andrei Prigorshnev 2023-06-14 19:34:38 +04:00 committed by GitHub
parent 2652354da3
commit e5c705af8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 149 additions and 147 deletions

View File

@ -288,6 +288,114 @@ describe Chat::MessageCreator do
end end
end end
context "with group mentions" do
it "creates chat mentions for group mentions where the group is mentionable" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1)
end
it "doesn't mention users twice if they are direct mentioned and group mentioned" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name} @#{admin1.username} and @#{admin2.username}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1)
end
it "creates chat mentions for group mentions and direct mentions" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name} @#{user2.username}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1).and change { user2.chat_mentions.count }.by(1)
end
it "creates chat mentions for group mentions and direct mentions" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name} @#{user_group.name}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1).and change { user2.chat_mentions.count }.by(1).and change {
user3.chat_mentions.count
}.by(1)
end
it "doesn't create chat mentions for group mentions where the group is un-mentionable" do
admin_group.update(mentionable_level: Group::ALIAS_LEVELS[:nobody])
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name}",
)
}.not_to change { Chat::Mention.count }
end
it "creates a chat mention without notification for acting user" do
message =
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "@#{user_group.name}",
).chat_message
mention = user1.chat_mentions.where(chat_message: message).first
expect(mention).to be_present
expect(mention.notification).to be_blank
end
end
context "when ignore_channel_wide_mention is enabled" do
before { user2.user_option.update(ignore_channel_wide_mention: true) }
it "when mentioning @all creates a mention without notification" do
message =
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hi! @all",
).chat_message
mention = user2.chat_mentions.where(chat_message: message).first
expect(mention).to be_present
expect(mention.notification).to be_nil
end
it "when mentioning @here creates a mention without notification" do
user2.update(last_seen_at: Time.now)
message =
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "@here",
).chat_message
mention = user2.chat_mentions.where(chat_message: message).first
expect(mention).to be_present
expect(mention.notification).to be_nil
end
end
it "doesn't create mention notifications for users without a membership record" do it "doesn't create mention notifications for users without a membership record" do
message = message =
described_class.create( described_class.create(
@ -476,7 +584,6 @@ describe Chat::MessageCreator do
expect(mentioned_user["status"]).to be_blank expect(mentioned_user["status"]).to be_blank
end end
end
it "creates a chat_mention record without notification when self mentioning" do it "creates a chat_mention record without notification when self mentioning" do
message = message =
@ -490,37 +597,6 @@ describe Chat::MessageCreator do
expect(mention).to be_present expect(mention).to be_present
expect(mention.notification).to be_nil expect(mention.notification).to be_nil
end end
context "when ignore_channel_wide_mention is enabled" do
before { user2.user_option.update(ignore_channel_wide_mention: true) }
it "when mentioning @all creates a mention without notification" do
message =
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hi! @all",
).chat_message
mention = user2.chat_mentions.where(chat_message: message).first
expect(mention).to be_present
expect(mention.notification).to be_nil
end
it "when mentioning @here creates a mention without notification" do
user2.update(last_seen_at: Time.now)
message =
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "@here",
).chat_message
mention = user2.chat_mentions.where(chat_message: message).first
expect(mention).to be_present
expect(mention.notification).to be_nil
end
end end
describe "replies" do describe "replies" do
@ -976,82 +1052,6 @@ describe Chat::MessageCreator do
end end
end end
describe "group mentions" do
it "creates chat mentions for group mentions where the group is mentionable" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1)
end
it "doesn't mention users twice if they are direct mentioned and group mentioned" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name} @#{admin1.username} and @#{admin2.username}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1)
end
it "creates chat mentions for group mentions and direct mentions" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name} @#{user2.username}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1).and change { user2.chat_mentions.count }.by(1)
end
it "creates chat mentions for group mentions and direct mentions" do
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name} @#{user_group.name}",
)
}.to change { admin1.chat_mentions.count }.by(1).and change {
admin2.chat_mentions.count
}.by(1).and change { user2.chat_mentions.count }.by(1).and change {
user3.chat_mentions.count
}.by(1)
end
it "doesn't create chat mentions for group mentions where the group is un-mentionable" do
admin_group.update(mentionable_level: Group::ALIAS_LEVELS[:nobody])
expect {
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "hello @#{admin_group.name}",
)
}.not_to change { Chat::Mention.count }
end
it "creates a chat mention without notification for acting user" do
message =
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "@#{user_group.name}",
).chat_message
mention = user1.chat_mentions.where(chat_message: message).first
expect(mention).to be_present
expect(mention.notification).to be_blank
end
end
describe "push notifications" do describe "push notifications" do
before do before do
Chat::UserChatChannelMembership.where( Chat::UserChatChannelMembership.where(

View File

@ -347,9 +347,8 @@ describe Chat::MessageUpdater do
expect(user2.chat_mentions.where(chat_message: chat_message).count).to eq(1) expect(user2.chat_mentions.where(chat_message: chat_message).count).to eq(1)
end end
end end
end
describe "group mentions" do describe "with group mentions" do
it "creates group mentions on update" do it "creates group mentions on update" do
chat_message = create_chat_message(user1, "ping nobody", public_chat_channel) chat_message = create_chat_message(user1, "ping nobody", public_chat_channel)
expect { expect {
@ -372,7 +371,9 @@ describe Chat::MessageUpdater do
chat_message: chat_message, chat_message: chat_message,
new_content: "ping @#{admin_group.name} @#{admin2.username}", new_content: "ping @#{admin_group.name} @#{admin2.username}",
) )
}.to change { admin1.chat_mentions.count }.by(1).and not_change { admin2.chat_mentions.count } }.to change { admin1.chat_mentions.count }.by(1).and not_change {
admin2.chat_mentions.count
}
end end
it "deletes old mentions when group mention is removed" do it "deletes old mentions when group mention is removed" do
@ -389,6 +390,7 @@ describe Chat::MessageUpdater do
expect(admin2.chat_mentions.where(chat_message: chat_message)).not_to be_present expect(admin2.chat_mentions.where(chat_message: chat_message)).not_to be_present
end end
end end
end
it "creates a chat_message_revision record and sets last_editor_id for the message" do it "creates a chat_message_revision record and sets last_editor_id for the message" do
old_message = "It's a thrsday!" old_message = "It's a thrsday!"