Files
mostlymatter/server/model/shared_channel_test.go
Agniva De Sarker b200a07881 v8.0 module release (#22975)
https://mattermost.atlassian.net/browse/MM-52079

```release-note
We upgrade the module version to 8.0. The new module path is github.com/mattermost-server/server/v8.
```


Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
2023-04-18 11:05:28 +05:30

67 строки
2.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSharedChannelIsValid(t *testing.T) {
id := NewId()
now := GetMillis()
data := []struct {
name string
sc *SharedChannel
valid bool
}{
{name: "Zero value", sc: &SharedChannel{}, valid: false},
{name: "Missing team_id", sc: &SharedChannel{ChannelId: id}, valid: false},
{name: "Missing create_at", sc: &SharedChannel{ChannelId: id, TeamId: id}, valid: false},
{name: "Missing update_at", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now}, valid: false},
{name: "Missing share_name", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now}, valid: false},
{name: "Invalid share_name", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "@test@"}, valid: false},
{name: "Too long share_name", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: strings.Repeat("01234567890", 100)}, valid: false},
{name: "Missing creator_id", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "test"}, valid: false},
{name: "Missing remote_id", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "test", CreatorId: id}, valid: false},
{name: "Valid shared channel", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "test", CreatorId: id, RemoteId: id}, valid: true},
}
for _, item := range data {
appErr := item.sc.IsValid()
if item.valid {
assert.Nil(t, appErr, item.name)
} else {
assert.NotNil(t, appErr, item.name)
}
}
}
func TestSharedChannelPreSave(t *testing.T) {
now := GetMillis()
o := SharedChannel{ChannelId: NewId(), ShareName: "test"}
o.PreSave()
require.GreaterOrEqual(t, o.CreateAt, now)
require.GreaterOrEqual(t, o.UpdateAt, now)
}
func TestSharedChannelPreUpdate(t *testing.T) {
now := GetMillis()
o := SharedChannel{ChannelId: NewId(), ShareName: "test"}
o.PreUpdate()
require.GreaterOrEqual(t, o.UpdateAt, now)
}