//go:build mysql package mysql import ( "os" "strings" "testing" "github.com/tinode/chat/server/store/types" ) func TestCanUseManagedReportsRequiresAllOrganizationVisibility(t *testing.T) { if !canUseManagedReports(organizationVisibility{Scope: orgVisibilityAll}) { t.Fatal("all visibility should be allowed to use managed report scope") } for _, scope := range []string{orgVisibilitySelf, orgVisibilityFriends, ""} { if canUseManagedReports(organizationVisibility{Scope: scope}) { t.Fatalf("scope %q should not be allowed to use managed report scope", scope) } } } func TestReportMemberScopeWhereIncludesDepartmentAndVisibility(t *testing.T) { where, args := reportMemberScopeWhere(organizationVisibility{Scope: orgVisibilityFriends, UserID: 42}, "dep_ops") joined := strings.Join(where, " AND ") if !strings.Contains(joined, "m.department_id=?") { t.Fatalf("department filter missing from where: %s", joined) } if !strings.Contains(joined, "im_friendships") { t.Fatalf("friend visibility filter missing from where: %s", joined) } if len(args) != 4 || args[0] != "dep_ops" || args[1] != int64(42) || args[2] != int64(42) || args[3] != types.RelationshipFriend { t.Fatalf("unexpected args: %#v", args) } } func TestGroupAdminAccessModeDoesNotGrantOwner(t *testing.T) { mode := groupAdminAccessMode() if !mode.IsAdmin() { t.Fatalf("admin mode should grant admin access: %s", mode.String()) } if mode.IsOwner() { t.Fatalf("admin mode must not grant owner access: %s", mode.String()) } } func TestMessageSearchDoesNotClearScannedHead(t *testing.T) { source, err := os.ReadFile("tenant_adapter.go") if err != nil { t.Fatal(err) } if strings.Contains(string(source), "msg.Head = kvMapFromJSON(msg.Head)") { t.Fatal("message search must not clear Head after sqlx StructScan has already decoded it") } }