feat(widget): 优化访客在线轨迹、GeoIP与多站点渠道
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"kefu-cloud/server/internal/model"
|
||||
)
|
||||
|
||||
func TestVisitorIsOnlineByHeartbeatAndLeave(t *testing.T) {
|
||||
now := time.Now()
|
||||
recent := now.Add(-20 * time.Second)
|
||||
stale := now.Add(-VisitorOnlineTimeout - time.Second)
|
||||
left := now.Add(-10 * time.Second)
|
||||
|
||||
if !VisitorIsOnline(&model.Session{Status: "active", LastSeenAt: &recent}, now) {
|
||||
t.Fatal("最近有心跳的进行中会话应在线")
|
||||
}
|
||||
if VisitorIsOnline(&model.Session{Status: "active", LastSeenAt: &stale}, now) {
|
||||
t.Fatal("超过 45 秒无心跳应离线")
|
||||
}
|
||||
if VisitorIsOnline(&model.Session{Status: "active", LastSeenAt: &recent, VisitorLeftAt: &left}, now) {
|
||||
t.Fatal("显式离开后应离线")
|
||||
}
|
||||
afterReturn := now.Add(-5 * time.Second)
|
||||
if !VisitorIsOnline(&model.Session{Status: "active", LastSeenAt: &afterReturn, VisitorLeftAt: &left}, now) {
|
||||
t.Fatal("离开后重新心跳应恢复在线")
|
||||
}
|
||||
if VisitorIsOnline(&model.Session{Status: "ended", LastSeenAt: &recent}, now) {
|
||||
t.Fatal("已结束会话不应在线")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user