51 lines
1.7 KiB
Go
51 lines
1.7 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)
|
|
}
|
|
}
|
|
|
|
func TestYouthModeOrdinaryMessageDoesNotReadDatabase(t *testing.T) {
|
|
oldSecurity := store.Security
|
|
security := &testSecurityStore{err: types.ErrInternal}
|
|
store.Security = security
|
|
defer func() { store.Security = oldSecurity }()
|
|
|
|
decision := imYouthModePolicyDecision(7, types.Uid(42), imYouthActionMessage, time.Now())
|
|
if !decision.Allowed {
|
|
t.Fatalf("ordinary message should continue to moderation: %#v", decision)
|
|
}
|
|
if security.youthModeReads != 0 {
|
|
t.Fatalf("ordinary message read youth settings %d times", security.youthModeReads)
|
|
}
|
|
}
|