18c9354095
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
143 lines
3.5 KiB
Go
143 lines
3.5 KiB
Go
package builders
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/i18nx"
|
|
)
|
|
|
|
func TestLocalizeConversationSummary(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
locale string
|
|
summary string
|
|
want string
|
|
}{
|
|
{
|
|
name: "image summary in english",
|
|
locale: i18nx.LocaleEnUS,
|
|
summary: "[图片]",
|
|
want: "[Image]",
|
|
},
|
|
{
|
|
name: "attachment summary in english",
|
|
locale: i18nx.LocaleEnUS,
|
|
summary: "[附件] spec.pdf",
|
|
want: "[Attachment] spec.pdf",
|
|
},
|
|
{
|
|
name: "recalled message in english",
|
|
locale: i18nx.LocaleEnUS,
|
|
summary: "该消息已撤回",
|
|
want: "This message was recalled.",
|
|
},
|
|
{
|
|
name: "business text is not translated",
|
|
locale: i18nx.LocaleEnUS,
|
|
summary: "客户反馈无法登录",
|
|
want: "客户反馈无法登录",
|
|
},
|
|
{
|
|
name: "chinese locale keeps existing summary",
|
|
locale: i18nx.LocaleZhCN,
|
|
summary: "[图片]",
|
|
want: "[图片]",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := localizeConversationSummary(tt.locale, tt.summary); got != tt.want {
|
|
t.Fatalf("localizeConversationSummary() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLocalizeRenderableMessageContent(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
locale string
|
|
content string
|
|
want string
|
|
}{
|
|
{
|
|
name: "recalled message in english",
|
|
locale: i18nx.LocaleEnUS,
|
|
content: "该消息已撤回",
|
|
want: "This message was recalled.",
|
|
},
|
|
{
|
|
name: "normal customer message is not translated",
|
|
locale: i18nx.LocaleEnUS,
|
|
content: "客户反馈无法登录",
|
|
want: "客户反馈无法登录",
|
|
},
|
|
{
|
|
name: "chinese locale keeps content",
|
|
locale: i18nx.LocaleZhCN,
|
|
content: "该消息已撤回",
|
|
want: "该消息已撤回",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := localizeRenderableMessageContent(tt.locale, tt.content); got != tt.want {
|
|
t.Fatalf("localizeRenderableMessageContent() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBuildMessageJSONDoesNotExposeSeqNo(t *testing.T) {
|
|
resp := BuildMessageWithReadStatesAndLocale(&models.Message{
|
|
ID: 1,
|
|
ConversationID: 2,
|
|
SenderType: enums.IMSenderTypeCustomer,
|
|
MessageType: enums.IMMessageTypeText,
|
|
Content: "hello",
|
|
}, nil, nil, nil, nil, nil, i18nx.DefaultLocale)
|
|
|
|
raw, err := json.Marshal(resp)
|
|
if err != nil {
|
|
t.Fatalf("marshal message response: %v", err)
|
|
}
|
|
if strings.Contains(string(raw), "seqNo") {
|
|
t.Fatalf("message response should not expose seqNo, got %s", raw)
|
|
}
|
|
}
|
|
|
|
func TestBuildAIMessageIncludesAgentAvatar(t *testing.T) {
|
|
const avatar = "https://cdn.example.com/ai-agent.png"
|
|
resp := BuildMessageWithReadStatesAndLocale(&models.Message{
|
|
ID: 3,
|
|
ConversationID: 2,
|
|
SenderType: enums.IMSenderTypeAI,
|
|
SenderID: 9,
|
|
MessageType: enums.IMMessageTypeText,
|
|
Content: "hello",
|
|
}, nil, nil, map[int64]*models.AIAgent{
|
|
9: {ID: 9, Name: "AI 客服", Avatar: avatar},
|
|
}, nil, nil, i18nx.DefaultLocale)
|
|
|
|
if resp.SenderName != "AI 客服" {
|
|
t.Fatalf("sender name = %q, want AI 客服", resp.SenderName)
|
|
}
|
|
if resp.SenderAvatar != avatar {
|
|
t.Fatalf("sender avatar = %q, want %q", resp.SenderAvatar, avatar)
|
|
}
|
|
}
|