disabling marksbot when third-party verifications if turned off

This commit is contained in:
onysd 2026-08-06 15:45:32 +03:00
parent 2491088e81
commit 818c9a58a3
7 changed files with 158 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"reflect"
"strings"
"testing"
privacyapp "telesrv/internal/app/privacy"
@ -644,6 +645,46 @@ func TestAcceptContactRequiresExistingContactRequest(t *testing.T) {
}
}
// marksbotSearchStore wraps memory.UserStore to fold domain.VerifierBotUser()
// into a matching Search result, since memory.UserStore.Create always assigns
// an id from its own auto-increment sequence and can never produce the fixed
// domain.VerifierBotUserID a real deployment seeds it under.
type marksbotSearchStore struct {
*memory.UserStore
}
func (s *marksbotSearchStore) Search(ctx context.Context, currentUserID int64, query, phoneQuery string, limit int) (domain.UserSearchResult, error) {
res, err := s.UserStore.Search(ctx, currentUserID, query, phoneQuery, limit)
if err != nil {
return res, err
}
if strings.Contains(strings.ToLower(query), "marks") {
res.Results = append(res.Results, domain.VerifierBotUser())
}
return res, nil
}
func TestSearchHidesMarksbotWhenThirdPartyVerificationHidden(t *testing.T) {
ctx := context.Background()
users := &marksbotSearchStore{UserStore: memory.NewUserStore()}
viewer, err := users.Create(ctx, domain.User{Phone: "15550000201", FirstName: "Viewer"})
if err != nil {
t.Fatalf("create viewer: %v", err)
}
visible := NewService(memory.NewContactStore(), users).Configure(WithHideThirdPartyVerification(false))
found, err := visible.Search(ctx, viewer.ID, "marksbot", 10)
if err != nil || len(found.Results) != 1 || found.Results[0].ID != domain.VerifierBotUserID {
t.Fatalf("Search (visible) = %+v err=%v, want @marksbot", found, err)
}
hidden := NewService(memory.NewContactStore(), users).Configure(WithHideThirdPartyVerification(true))
found, err = hidden.Search(ctx, viewer.ID, "marksbot", 10)
if err != nil || len(found.Results) != 0 {
t.Fatalf("Search (hidden) = %+v err=%v, want no results", found, err)
}
}
func TestSearchFindsOnlyActiveCollectibleUsernames(t *testing.T) {
ctx := context.Background()
users := memory.NewUserStore()