Files
kefu_cloud/server/internal/handler/assignment_test.go
T
yml2213 216ab2c85a 支持可配置的会话自动分配策略
- 租户可设置负载最低或轮询,以及每位坐席最大进行中会话数
- 自动分配按策略过滤在线一线客服,满并发则保持排队
- 系统设置「客服分配规则」页可保存上述配置
2026-07-15 15:07:41 +08:00

50 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import (
"testing"
"kefu-sys/server/internal/model"
)
func TestPickLeastLoadedPrefersFewerSessions(t *testing.T) {
a := model.User{ID: 1}
b := model.User{ID: 2}
c := model.User{ID: 3}
candidates := []model.User{a, b, c}
counts := map[uint]int64{1: 3, 2: 1, 3: 1}
got := pickLeastLoadedAgent(candidates, counts)
if got == nil || got.ID != 2 {
t.Fatalf("期望 id=2(平局取更小 id),got=%v", got)
}
}
func TestPickRoundRobinAdvances(t *testing.T) {
candidates := []model.User{{ID: 10}, {ID: 20}, {ID: 30}}
last := uint(10)
got := pickRoundRobinAgent(candidates, &last)
if got == nil || got.ID != 20 {
t.Fatalf("期望下一位 20got=%v", got)
}
last = 30
got = pickRoundRobinAgent(candidates, &last)
if got == nil || got.ID != 10 {
t.Fatalf("期望绕回 10got=%v", got)
}
got = pickRoundRobinAgent(candidates, nil)
if got == nil || got.ID != 10 {
t.Fatalf("无游标时期望第一位 10got=%v", got)
}
}
func TestNormalizeAssignStrategy(t *testing.T) {
if normalizeAssignStrategy("round_robin") != assignStrategyRoundRobin {
t.Fatal("round_robin")
}
if normalizeAssignStrategy("") != assignStrategyLeastLoad {
t.Fatal("default least_load")
}
if normalizeAssignStrategy("unknown") != assignStrategyLeastLoad {
t.Fatal("unknown -> least_load")
}
}