Add runnable unit tests (no external services required): - internal/utils: FormatVector/ParseEmbedding (all type branches + round-trip), AverageVector, TopWords (min-length + stopword filtering + ranking) - internal/config: getEnvBool, splitComma, Load defaults/override - internal/server: determinePlatform (did/npub/@-handle/64-hex/dotted) and platformFromString - internal/twitter: mocked Twitter API v2 (empty-token error, fetch+parse, max_results clamping, non-200 error) - internal/activitypub: mocked Mastodon API (constructor validation, GetLatestNPosts, GetPost, non-200 error) Not covered (require live services / heavy mocking): store sqlc queries + pgvector migrations (need Postgres), nostr client (needs a relay), ollama client (wraps the ollama/go API over HTTP), and server orchestration (requestStyleProfile, enrichCrossPlatform, fetchProfilePosts, getSimilarProfiles need a DB + platform clients). Co-Authored-By: Claude (AI assistant) <noreply@anthropic.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package server
|
|
|
|
import "testing"
|
|
|
|
func TestDeterminePlatform(t *testing.T) {
|
|
cases := []struct {
|
|
author string
|
|
want platform
|
|
err bool
|
|
}{
|
|
{"did:plc:abc123", Bluesky, false},
|
|
{"npub1qwerty", Nostr, false},
|
|
{"@user@host.social", ActivityPub, false},
|
|
{"@user.bsky.social", Bluesky, false},
|
|
{"@user", Twitter, false},
|
|
{"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", Nostr, false},
|
|
{"user.bsky.social", Bluesky, false},
|
|
{"example.com", Bluesky, false},
|
|
{"justhandle", -1, true},
|
|
{"", -1, true},
|
|
}
|
|
for _, c := range cases {
|
|
got, err := determinePlatform(c.author)
|
|
if c.err {
|
|
if err == nil {
|
|
t.Fatalf("%q: expected error", c.author)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("%q: unexpected error %v", c.author, err)
|
|
}
|
|
if got != c.want {
|
|
t.Fatalf("%q: got %v want %v", c.author, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPlatformFromString(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want platform
|
|
ok bool
|
|
}{
|
|
{"Bluesky", Bluesky, true},
|
|
{"ActivityPub", ActivityPub, true},
|
|
{"Nostr", Nostr, true},
|
|
{"Twitter", Twitter, true},
|
|
{"nope", -1, false},
|
|
}
|
|
for _, c := range cases {
|
|
got, ok := platformFromString(c.in)
|
|
if ok != c.ok || got != c.want {
|
|
t.Fatalf("%q: got %v ok %v, want %v %v", c.in, got, ok, c.want, c.ok)
|
|
}
|
|
}
|
|
}
|