ultisuite-backend/internal/api/contacts/match_score_test.go
R3D347HR4Y 556d5f416d Enhance API and configuration for contact discovery and public sharing
- Introduced new endpoints for contact discovery, including scanning, listing, and managing discovered contacts.
- Implemented retry logic for handling missing DAV credentials during contact operations.
- Added public share functionality for drive API, allowing users to manage public shares, including upload, delete, and rename operations.
- Updated Nextcloud configuration to support public share links and improved error handling for public share permissions.
- Enhanced logging and validation across contact and drive APIs for better error tracking and user feedback.
- Added tests for new contact matching and ranking functionalities to ensure accuracy and reliability.
2026-06-06 20:27:02 +02:00

43 lines
1.1 KiB
Go

package contacts
import (
"testing"
"github.com/ultisuite/ulti-backend/internal/nextcloud"
)
func TestFieldMatchScoreExactAndPrefix(t *testing.T) {
if got := fieldMatchScore("Alice Martin", "alice martin"); got != 1 {
t.Fatalf("exact match: got %v want 1", got)
}
prefix := fieldMatchScore("alice@example.com", "alice")
if prefix < 0.95 {
t.Fatalf("email prefix too low: %v", prefix)
}
}
func TestRankContactsByQueryOrder(t *testing.T) {
contacts := []nextcloud.Contact{
{FullName: "Jonathan Smith", Email: "jonathan@corp.com"},
{FullName: "Jon Smith", Email: "jon@corp.com"},
{FullName: "Bob Builder", Email: "bob@corp.com"},
}
ranked := rankContactsByQuery(contacts, "jon")
if len(ranked) != 2 {
t.Fatalf("expected 2 matches, got %d", len(ranked))
}
if ranked[0].FullName != "Jon Smith" {
t.Fatalf("expected Jon Smith first, got %q", ranked[0].FullName)
}
}
func TestRankContactsByQueryNoFuzzy(t *testing.T) {
contacts := []nextcloud.Contact{
{FullName: "Jonathan", Email: "jonathan@corp.com"},
}
ranked := rankContactsByQuery(contacts, "jhn")
if len(ranked) != 0 {
t.Fatalf("expected no fuzzy match, got %d", len(ranked))
}
}