mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-13 21:17:49 -04:00
--------- Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Nick Misasi <nick.misasi@mattermost.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Matthew Birtch <mattbirtch@gmail.com> Co-authored-by: Mattermost Build <build@mattermost.com>
86 lines
2.5 KiB
Go
86 lines
2.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestWithAutoTranslationPath(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
path AutoTranslationPath
|
|
expected AutoTranslationPath
|
|
}{
|
|
{
|
|
name: "create path",
|
|
path: AutoTranslationPathCreate,
|
|
expected: AutoTranslationPathCreate,
|
|
},
|
|
{
|
|
name: "edit path",
|
|
path: AutoTranslationPathEdit,
|
|
expected: AutoTranslationPathEdit,
|
|
},
|
|
{
|
|
name: "fetch path",
|
|
path: AutoTranslationPathFetch,
|
|
expected: AutoTranslationPathFetch,
|
|
},
|
|
{
|
|
name: "websocket path",
|
|
path: AutoTranslationPathWebSocket,
|
|
expected: AutoTranslationPathWebSocket,
|
|
},
|
|
{
|
|
name: "push notification path",
|
|
path: AutoTranslationPathPushNotification,
|
|
expected: AutoTranslationPathPushNotification,
|
|
},
|
|
{
|
|
name: "email notification path",
|
|
path: AutoTranslationPathEmailNotification,
|
|
expected: AutoTranslationPathEmailNotification,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
ctx = WithAutoTranslationPath(ctx, tt.path)
|
|
|
|
got := GetAutoTranslationPath(ctx)
|
|
assert.Equal(t, tt.expected, got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetAutoTranslationPathUnknown(t *testing.T) {
|
|
t.Run("no path set returns unknown", func(t *testing.T) {
|
|
ctx := context.Background()
|
|
got := GetAutoTranslationPath(ctx)
|
|
assert.Equal(t, AutoTranslationPathUnknown, got)
|
|
})
|
|
|
|
t.Run("wrong type in context returns unknown", func(t *testing.T) {
|
|
ctx := context.WithValue(context.Background(), ContextKeyAutoTranslationPath, "string_not_type")
|
|
got := GetAutoTranslationPath(ctx)
|
|
assert.Equal(t, AutoTranslationPathUnknown, got)
|
|
})
|
|
}
|
|
|
|
func TestAutoTranslationPathConstants(t *testing.T) {
|
|
t.Run("all constants are defined", func(t *testing.T) {
|
|
assert.Equal(t, AutoTranslationPath("create"), AutoTranslationPathCreate)
|
|
assert.Equal(t, AutoTranslationPath("edit"), AutoTranslationPathEdit)
|
|
assert.Equal(t, AutoTranslationPath("fetch"), AutoTranslationPathFetch)
|
|
assert.Equal(t, AutoTranslationPath("websocket"), AutoTranslationPathWebSocket)
|
|
assert.Equal(t, AutoTranslationPath("push_notification"), AutoTranslationPathPushNotification)
|
|
assert.Equal(t, AutoTranslationPath("email_notification"), AutoTranslationPathEmailNotification)
|
|
assert.Equal(t, AutoTranslationPath("unknown"), AutoTranslationPathUnknown)
|
|
})
|
|
}
|