package connection import ( "testing" "time" "github.com/bluesky-social/indigo/atproto/syntax" ) func TestFindForTarget_PicksMostRecent(t *testing.T) { target := syntax.DID(didA) older := ListEntry{URI: "at://x/c/old", With: target, ConnectedAt: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), EventURI: "at://x/e/1"} newer := ListEntry{URI: "at://x/c/new", With: target, ConnectedAt: time.Date(2026, 6, 1, 0, 0, 0, 0, time.UTC), EventURI: "at://x/e/2"} other := ListEntry{URI: "at://x/c/z", With: syntax.DID(didB), ConnectedAt: time.Now()} got, ok := FindForTarget([]ListEntry{older, other, newer}, target) if !ok { t.Fatal("expected to find target") } if got.URI != "at://x/c/new" { t.Errorf("URI = %s, want at://x/c/new", got.URI) } } func TestFindForTarget_NotFound(t *testing.T) { _, ok := FindForTarget([]ListEntry{{With: syntax.DID(didB)}}, syntax.DID(didA)) if ok { t.Error("expected not found") } }