mattermost/server/public/model/command_args_test.go
Jesse Hallam bb02b35048
Expose public/ API as submodule (#23345)
* model -> public/model

* plugin -> public/plugin

* public/model/utils -> public/utils

* platform/shared/mlog -> public/shared/mlog

* platform/shared/i18n -> public/shared/i18n

* platform/shared/markdown -> public/shared/markdown

* platform/services/timezones -> public/shared/timezones

* channels/einterfaces -> einterfaces

* expose public/ submodule

* go mod tidy

* .github: cache-dependency-path, setup-go-work

* modules-tidy for public/ too

* remove old gomodtidy
2023-05-10 13:07:02 -03:00

108 lines
2.3 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCommandArgs_AddUserMention(t *testing.T) {
fixture := []struct {
args CommandArgs
mentions map[string]string
expected CommandArgs
}{
{
CommandArgs{},
map[string]string{"one": "1"},
CommandArgs{
UserMentions: map[string]string{"one": "1"},
},
},
{
CommandArgs{
ChannelMentions: map[string]string{"channel": "1"},
},
map[string]string{"one": "1"},
CommandArgs{
UserMentions: map[string]string{"one": "1"},
ChannelMentions: map[string]string{"channel": "1"},
},
},
{
CommandArgs{
UserMentions: map[string]string{"one": "1"},
},
map[string]string{"one": "1"},
CommandArgs{
UserMentions: map[string]string{"one": "1"},
},
},
{
CommandArgs{},
map[string]string{"one": "1", "two": "2", "three": "3"},
CommandArgs{
UserMentions: map[string]string{"one": "1", "two": "2", "three": "3"},
},
},
}
for _, data := range fixture {
for name, id := range data.mentions {
data.args.AddUserMention(name, id)
}
require.Equal(t, data.args, data.expected)
}
}
func TestCommandArgs_AddChannelMention(t *testing.T) {
fixture := []struct {
args CommandArgs
mentions map[string]string
expected CommandArgs
}{
{
CommandArgs{},
map[string]string{"one": "1"},
CommandArgs{
ChannelMentions: map[string]string{"one": "1"},
},
},
{
CommandArgs{
UserMentions: map[string]string{"user": "1"},
},
map[string]string{"one": "1"},
CommandArgs{
ChannelMentions: map[string]string{"one": "1"},
UserMentions: map[string]string{"user": "1"},
},
},
{
CommandArgs{
ChannelMentions: map[string]string{"one": "1"},
},
map[string]string{"one": "1"},
CommandArgs{
ChannelMentions: map[string]string{"one": "1"},
},
},
{
CommandArgs{},
map[string]string{"one": "1", "two": "2", "three": "3"},
CommandArgs{
ChannelMentions: map[string]string{"one": "1", "two": "2", "three": "3"},
},
},
}
for _, data := range fixture {
for name, id := range data.mentions {
data.args.AddChannelMention(name, id)
}
require.Equal(t, data.args, data.expected)
}
}