mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Posts * Add missing translation * Fix internal store marshaling * [MM-22051] Remove To/From JSON (Channels) (#18116) * Channels * Channel members * ChannelSearch * Channel categories, list, sidebar, stats, view * Fix conversions * [MM-22051] Remove To/From JSON (Users) (#18121) * User related structs * Fix return * Team related structures (#18127) * [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130) * Status * Bot * Reaction * Thread * FileInfo * Some fixes * Translations update from Weblate (#18143) * Translated using Weblate (German) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ * Translated using Weblate (German) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Translated using Weblate (English (Australia)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/ * Translated using Weblate (Bulgarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/ * Translated using Weblate (Japanese) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/ * Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/ Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> * [MM-22051] Remove To/From JSON methods from model (#18138) * Scheme * Role * Session * Config * Status * Fix logic * Emoji * GuestsInvite * Group * Command * ClusterInfo * License * Job * System * Plugin * Command2 * IncomingWebhook * OutgoingWebhook * Fix tests * Update traslation * Some fixes * Add missing return * Simplify * Make Config.ToJSONFiltered() return []byte * Make Busy.ToJSON() return []byte * Include error in log * Split logic * [MM-22051] Remove To/From JSON (final) (#18150) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * [MM-23280] Fix linting for ToJSON/FromJSON (#18153) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * Fix linting for ToJSON/FromJSON * Fix conversions Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
137 lines
4.4 KiB
Go
137 lines
4.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestOutgoingWebhookIsValid(t *testing.T) {
|
|
o := OutgoingWebhook{}
|
|
assert.NotNil(t, o.IsValid(), "empty declaration should be invalid")
|
|
|
|
o.Id = NewId()
|
|
assert.NotNilf(t, o.IsValid(), "Id = NewId; %s should be invalid", o.Id)
|
|
|
|
o.CreateAt = GetMillis()
|
|
assert.NotNilf(t, o.IsValid(), "CreateAt = GetMillis; %d should be invalid", o.CreateAt)
|
|
|
|
o.UpdateAt = GetMillis()
|
|
assert.NotNilf(t, o.IsValid(), "UpdateAt = GetMillis; %d should be invalid", o.UpdateAt)
|
|
|
|
o.CreatorId = "123"
|
|
assert.NotNilf(t, o.IsValid(), "CreatorId %s should be invalid", o.CreatorId)
|
|
|
|
o.CreatorId = NewId()
|
|
assert.NotNilf(t, o.IsValid(), "CreatorId = NewId; %s should be invalid", o.CreatorId)
|
|
|
|
o.Token = "123"
|
|
assert.NotNilf(t, o.IsValid(), "Token %s should be invalid", o.Token)
|
|
|
|
o.Token = NewId()
|
|
assert.NotNilf(t, o.IsValid(), "Token = NewId; %s should be invalid", o.Token)
|
|
|
|
o.ChannelId = "123"
|
|
assert.NotNilf(t, o.IsValid(), "ChannelId %s should be invalid", o.ChannelId)
|
|
|
|
o.ChannelId = NewId()
|
|
assert.NotNilf(t, o.IsValid(), "ChannelId = NewId; %s should be invalid", o.ChannelId)
|
|
|
|
o.TeamId = "123"
|
|
assert.NotNilf(t, o.IsValid(), "TeamId %s should be invalid", o.TeamId)
|
|
|
|
o.TeamId = NewId()
|
|
assert.NotNilf(t, o.IsValid(), "TeamId = NewId; %s should be invalid", o.TeamId)
|
|
|
|
o.CallbackURLs = []string{"nowhere.com/"}
|
|
assert.NotNilf(t, o.IsValid(), "%v for CallbackURLs should be invalid", o.CallbackURLs)
|
|
|
|
o.CallbackURLs = []string{"http://nowhere.com/"}
|
|
assert.Nilf(t, o.IsValid(), "%v for CallbackURLs should be valid", o.CallbackURLs)
|
|
|
|
o.DisplayName = strings.Repeat("1", 65)
|
|
assert.NotNilf(t, o.IsValid(), "DisplayName length %d invalid, max length 64", len(o.DisplayName))
|
|
|
|
o.DisplayName = strings.Repeat("1", 64)
|
|
assert.Nilf(t, o.IsValid(), "DisplayName length %d should be valid, max length 64", len(o.DisplayName))
|
|
|
|
o.Description = strings.Repeat("1", 501)
|
|
assert.NotNilf(t, o.IsValid(), "Description length %d should be invalid, max length 500", len(o.Description))
|
|
|
|
o.Description = strings.Repeat("1", 500)
|
|
assert.Nilf(t, o.IsValid(), "Description length %d should be valid, max length 500", len(o.Description))
|
|
|
|
o.ContentType = strings.Repeat("1", 129)
|
|
assert.NotNilf(t, o.IsValid(), "ContentType length %d should be invalid, max length 128", len(o.ContentType))
|
|
|
|
o.ContentType = strings.Repeat("1", 128)
|
|
assert.Nilf(t, o.IsValid(), "ContentType length %d should be valid", len(o.ContentType))
|
|
|
|
o.Username = strings.Repeat("1", 65)
|
|
assert.NotNilf(t, o.IsValid(), "Username length %d should be invalid, max length 64", len(o.Username))
|
|
|
|
o.Username = strings.Repeat("1", 64)
|
|
assert.Nilf(t, o.IsValid(), "Username length %d should be valid", len(o.Username))
|
|
|
|
o.IconURL = strings.Repeat("1", 1025)
|
|
assert.NotNilf(t, o.IsValid(), "IconURL length %d should be invalid, max length 1024", len(o.IconURL))
|
|
|
|
o.IconURL = strings.Repeat("1", 1024)
|
|
assert.Nilf(t, o.IsValid(), "IconURL length %d should be valid", len(o.IconURL))
|
|
}
|
|
|
|
func TestOutgoingWebhookPayloadToFormValues(t *testing.T) {
|
|
p := &OutgoingWebhookPayload{
|
|
Token: "Token",
|
|
TeamId: "TeamId",
|
|
TeamDomain: "TeamDomain",
|
|
ChannelId: "ChannelId",
|
|
ChannelName: "ChannelName",
|
|
Timestamp: 123000,
|
|
UserId: "UserId",
|
|
UserName: "UserName",
|
|
PostId: "PostId",
|
|
Text: "Text",
|
|
TriggerWord: "TriggerWord",
|
|
FileIds: "FileIds",
|
|
}
|
|
v := url.Values{}
|
|
v.Set("token", "Token")
|
|
v.Set("team_id", "TeamId")
|
|
v.Set("team_domain", "TeamDomain")
|
|
v.Set("channel_id", "ChannelId")
|
|
v.Set("channel_name", "ChannelName")
|
|
v.Set("timestamp", "123")
|
|
v.Set("user_id", "UserId")
|
|
v.Set("user_name", "UserName")
|
|
v.Set("post_id", "PostId")
|
|
v.Set("text", "Text")
|
|
v.Set("trigger_word", "TriggerWord")
|
|
v.Set("file_ids", "FileIds")
|
|
got := p.ToFormValues()
|
|
want := v.Encode()
|
|
assert.Equalf(t, got, want, "Got %+v, wanted %+v", got, want)
|
|
}
|
|
|
|
func TestOutgoingWebhookPreSave(t *testing.T) {
|
|
o := OutgoingWebhook{}
|
|
o.PreSave()
|
|
}
|
|
|
|
func TestOutgoingWebhookPreUpdate(t *testing.T) {
|
|
o := OutgoingWebhook{}
|
|
o.PreUpdate()
|
|
}
|
|
|
|
func TestOutgoingWebhookTriggerWordStartsWith(t *testing.T) {
|
|
o := OutgoingWebhook{Id: NewId()}
|
|
o.TriggerWords = append(o.TriggerWords, "foo")
|
|
assert.True(t, o.TriggerWordStartsWith("foobar"), "Should return true")
|
|
assert.False(t, o.TriggerWordStartsWith("barfoo"), "Should return false")
|
|
}
|