Files
im_server/server/im_security_policy_runtime_test.go
T

36 lines
1.1 KiB
Go

package main
import (
"testing"
"time"
"github.com/tinode/chat/server/store"
"github.com/tinode/chat/server/store/types"
)
func TestYouthModeNightQuietRestrictsCalls(t *testing.T) {
oldSecurity := store.Security
uid := types.Uid(42)
store.Security = &testSecurityStore{youthMode: &types.YouthModeSettings{
UserID: uid,
Enabled: true,
PolicyVersion: 3,
Restrictions: []string{"night_quiet", "content_filter", "payment_guard"},
}}
defer func() { store.Security = oldSecurity }()
quietTime := time.Date(2026, 9, 18, 23, 30, 0, 0, time.Local)
decision := imYouthModePolicyDecision(7, uid, imYouthActionCall, quietTime)
if decision.Allowed {
t.Fatal("night quiet should restrict call initiation")
}
if decision.Reason != imReasonYouthRestricted || decision.Details["restriction"] != "night_quiet" || decision.Details["policy_version"] != 3 {
t.Fatalf("unexpected decision: %#v", decision)
}
daytime := time.Date(2026, 9, 18, 10, 0, 0, 0, time.Local)
if decision = imYouthModePolicyDecision(7, uid, imYouthActionCall, daytime); !decision.Allowed {
t.Fatalf("daytime call should be allowed: %#v", decision)
}
}