mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
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.
119 lines
4.1 KiB
Go
119 lines
4.1 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package sharedchannel
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
"github.com/hanzoteam/server/server/public/shared/i18n"
|
|
"github.com/hanzoteam/server/server/public/shared/mlog"
|
|
)
|
|
|
|
func TestRemoteClusterDisplayName(t *testing.T) {
|
|
t.Run("nil remote", func(t *testing.T) {
|
|
assert.Equal(t, "", remoteClusterDisplayName(nil))
|
|
})
|
|
|
|
t.Run("only RemoteId set", func(t *testing.T) {
|
|
rc := &model.RemoteCluster{RemoteId: "rid-abc"}
|
|
assert.Equal(t, "rid-abc", remoteClusterDisplayName(rc))
|
|
})
|
|
|
|
t.Run("Name used when DisplayName empty", func(t *testing.T) {
|
|
rc := &model.RemoteCluster{RemoteId: "rid-abc", Name: "internal-name"}
|
|
assert.Equal(t, "internal-name", remoteClusterDisplayName(rc))
|
|
})
|
|
|
|
t.Run("DisplayName preferred over Name and RemoteId", func(t *testing.T) {
|
|
rc := &model.RemoteCluster{
|
|
RemoteId: "rid-abc",
|
|
Name: "internal-name",
|
|
DisplayName: "Pretty Workspace",
|
|
}
|
|
assert.Equal(t, "Pretty Workspace", remoteClusterDisplayName(rc))
|
|
})
|
|
}
|
|
|
|
func TestMessageForSharedChannelStatePost(t *testing.T) {
|
|
t.Run("shared", func(t *testing.T) {
|
|
props := model.StringInterface{
|
|
model.PostPropsSharedChannelState: model.SharedChannelStatePostValueShared,
|
|
model.PostPropsSharedChannelWorkspaceName: "Acme",
|
|
}
|
|
got := messageForSharedChannelStatePost(props)
|
|
assert.Equal(t, i18n.T("shared_channel.system_message.now_shared", map[string]any{"WorkspaceName": "Acme"}), got)
|
|
})
|
|
|
|
t.Run("unshared with known workspace", func(t *testing.T) {
|
|
props := model.StringInterface{
|
|
model.PostPropsSharedChannelState: model.SharedChannelStatePostValueUnshared,
|
|
model.PostPropsSharedChannelWorkspaceName: "Acme",
|
|
}
|
|
got := messageForSharedChannelStatePost(props)
|
|
assert.Equal(t, i18n.T("shared_channel.system_message.no_longer_shared", map[string]any{"WorkspaceName": "Acme"}), got)
|
|
})
|
|
|
|
t.Run("unshared without workspace name", func(t *testing.T) {
|
|
props := model.StringInterface{
|
|
model.PostPropsSharedChannelState: model.SharedChannelStatePostValueUnshared,
|
|
}
|
|
got := messageForSharedChannelStatePost(props)
|
|
assert.Equal(t, i18n.T("shared_channel.system_message.no_longer_shared_unknown"), got)
|
|
})
|
|
|
|
t.Run("default empty or unknown state uses unknown unshared copy", func(t *testing.T) {
|
|
assert.Equal(t,
|
|
i18n.T("shared_channel.system_message.no_longer_shared_unknown"),
|
|
messageForSharedChannelStatePost(model.StringInterface{}),
|
|
)
|
|
assert.Equal(t,
|
|
i18n.T("shared_channel.system_message.no_longer_shared_unknown"),
|
|
messageForSharedChannelStatePost(model.StringInterface{
|
|
model.PostPropsSharedChannelState: "unexpected",
|
|
}),
|
|
)
|
|
})
|
|
}
|
|
|
|
func TestPostChannelUnsharedWithWorkspace_emptyWorkspaceName(t *testing.T) {
|
|
mockServer := &MockServerIface{}
|
|
logger := mlog.CreateConsoleTestLogger(t)
|
|
mockServer.On("Log").Return(logger)
|
|
|
|
mockApp := &MockAppIface{}
|
|
scs := &Service{
|
|
server: mockServer,
|
|
app: mockApp,
|
|
}
|
|
|
|
bot := &model.Bot{UserId: model.NewId()}
|
|
mockApp.On("GetSystemBot", mock.Anything).Return(bot, (*model.AppError)(nil))
|
|
|
|
mockApp.On("CreatePost", mock.Anything, mock.AnythingOfType("*model.Post"), mock.AnythingOfType("*model.Channel"), mock.Anything).
|
|
Run(func(args mock.Arguments) {
|
|
post := args.Get(1).(*model.Post)
|
|
ch := args.Get(2).(*model.Channel)
|
|
|
|
assert.Equal(t, model.PostTypeSharedChannelState, post.Type)
|
|
assert.Equal(t, bot.UserId, post.UserId)
|
|
assert.Equal(t, ch.Id, post.ChannelId)
|
|
assert.Equal(t, model.SharedChannelStatePostValueUnshared, post.GetProps()[model.PostPropsSharedChannelState])
|
|
_, hasWorkspaceName := post.GetProps()[model.PostPropsSharedChannelWorkspaceName]
|
|
assert.False(t, hasWorkspaceName)
|
|
assert.Equal(t,
|
|
i18n.T("shared_channel.system_message.no_longer_shared_unknown"),
|
|
post.Message,
|
|
)
|
|
}).Return(&model.Post{}, false, (*model.AppError)(nil))
|
|
|
|
channel := &model.Channel{Id: model.NewId(), TeamId: model.NewId()}
|
|
scs.postChannelUnsharedWithWorkspace(channel, "")
|
|
|
|
mockApp.AssertExpectations(t)
|
|
}
|