Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

200 lines
5.8 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package slashcommands
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/public/shared/i18n"
)
func TestMuteCommandNoChannel(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
channel1M, channel1MError := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
assert.Nil(t, channel1MError, "User is not a member of channel 1")
assert.NotEqual(
t,
channel1M.NotifyProps[model.MarkUnreadNotifyProp],
model.ChannelNotifyMention,
"Channel shouldn't be muted on initial setup",
)
cmd := &MuteProvider{}
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.no_channel.error", resp.Text)
}
func TestMuteCommandNoArgs(t *testing.T) {
th := setup(t).initBasic(t)
channel1 := th.BasicChannel
channel1M, _ := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
assert.Equal(t, model.ChannelNotifyAll, channel1M.NotifyProps[model.MarkUnreadNotifyProp])
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_mute", resp.Text)
// Now unmute the channel
time.Sleep(time.Millisecond)
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_unmute", resp.Text)
}
func TestMuteCommandSpecificChannel(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.ChannelTypeOpen,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, true)
channel2M, _ := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, channel2.Name)
assert.Equal(t, "api.command_mute.success_mute", resp.Text)
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.ChannelNotifyMention, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
// Now unmute the channel
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "~"+channel2.Name)
assert.Equal(t, "api.command_mute.success_unmute", resp.Text)
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
}
func TestMuteCommandNotMember(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.ChannelTypeOpen,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, false)
cmd := &MuteProvider{}
// Muting a channel that the user is not a member of should return
// the same error as a non-existent channel to prevent channel enumeration
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, channel2.Name)
assert.Equal(t, "api.command_mute.error", resp.Text)
}
func TestMuteCommandNotChannel(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "~noexists")
assert.Equal(t, "api.command_mute.error", resp.Text)
}
func TestMuteCommandDMChannel(t *testing.T) {
th := setup(t).initBasic(t)
if testing.Short() {
t.SkipNow()
}
channel2, _ := th.App.GetOrCreateDirectChannel(th.Context, th.BasicUser.Id, th.BasicUser2.Id)
channel2M, _ := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel2.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_mute_direct_msg", resp.Text)
time.Sleep(time.Millisecond)
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.ChannelNotifyMention, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
// Now unmute the channel
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel2.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_unmute_direct_msg", resp.Text)
time.Sleep(time.Millisecond)
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
}