Files
team/server/public/model/autotranslation_test.go
0f7e5a1468 Autotranslations MVP (#34696)
---------

Co-authored-by: Elias Nahum <[email protected]>

Co-authored-by: Nick Misasi <[email protected]>

Co-authored-by: Matthew Birtch <[email protected]>
Co-authored-by: Mattermost Build <[email protected]>

Co-authored-by: Hanzo Dev <[email protected]>
2026-01-26 17:05:34 -05:00

87 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)
})
}