Files
mostlymatter/server/channels/app/mention_results_test.go
Harrison Healey a78710c2a6 MM-54201 Refactor mention parsing in preparation for multi-word mentions (#25030)
* MM-54201 Move ExplicitMentions to its own file and rename it (#24932)

* MM-54201 Move ExplicitMentions to its own file and rename it

* Fix vet

* MM-54201 Refactor current mention parsing into MentionParserStandard (#24936)

* MM-54201 Refactor current mention parsing into MentionParserStandard

* Fix vet

* MM-54201 Unify user and group mention parsing logic (#24937)

* MM-54201 Add MentionKeywords type

* MM-54201 Move group mentions into MentionKeywords

* Fix flaky test caused by random iteration order

* Update server/channels/app/mention_results.go

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>

* Address feedback

---------

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>

---------

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
2023-10-23 12:37:58 -04:00

65 строки
1.5 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/stretchr/testify/assert"
)
func TestAddMention(t *testing.T) {
t.Run("should initialize Mentions and store new mentions", func(t *testing.T) {
m := &MentionResults{}
userID1 := model.NewId()
userID2 := model.NewId()
m.addMention(userID1, KeywordMention)
m.addMention(userID2, CommentMention)
assert.Equal(t, map[string]MentionType{
userID1: KeywordMention,
userID2: CommentMention,
}, m.Mentions)
})
t.Run("should replace existing mentions with higher priority ones", func(t *testing.T) {
m := &MentionResults{}
userID1 := model.NewId()
userID2 := model.NewId()
m.addMention(userID1, ThreadMention)
m.addMention(userID2, DMMention)
m.addMention(userID1, ChannelMention)
m.addMention(userID2, KeywordMention)
assert.Equal(t, map[string]MentionType{
userID1: ChannelMention,
userID2: KeywordMention,
}, m.Mentions)
})
t.Run("should not replace high priority mentions with low priority ones", func(t *testing.T) {
m := &MentionResults{}
userID1 := model.NewId()
userID2 := model.NewId()
m.addMention(userID1, KeywordMention)
m.addMention(userID2, CommentMention)
m.addMention(userID1, DMMention)
m.addMention(userID2, ThreadMention)
assert.Equal(t, map[string]MentionType{
userID1: KeywordMention,
userID2: CommentMention,
}, m.Mentions)
})
}