On the entry form, "Fill in the empty boxes" reads their website. Links, social accounts and feeds come straight from the pages (no guessing); the AI drafts the name if missing, a description, keywords, hashtags, and talking points set against the company profile for the relationship chosen. Typed values stay, nothing is saved until Save, and the form says which boxes were filled. Website reading moves from the profile draft into internal/site, shared by both, and now also collects links and declared RSS/Atom feeds (comment feeds skipped; Fill takes up to three). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.7 KiB
Go
83 lines
2.7 KiB
Go
package site
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadFindsLinksAndFeeds(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "text/html")
|
|
w.Write([]byte(`<html><head><title>Rival</title>
|
|
<link rel="alternate" type="application/rss+xml" href="/feed.xml">
|
|
<link rel="alternate" type="application/rss+xml" title="Rival » Comments Feed" href="/c.xml">
|
|
<link rel="alternate" type="application/rss+xml" href="/comments/feed/">
|
|
<link rel="stylesheet" href="/x.css"></head>
|
|
<body><a href="/about">About</a> <a href="https://x.com/rivalhq">X</a> <a href="mailto:hi@rival.example">Mail</a></body></html>`))
|
|
})
|
|
mux.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
w.Write([]byte(`<link type="application/atom+xml" rel="alternate" href="https://rival.example/atom">
|
|
<a href="https://twitter.com/someone_else">Them</a>`))
|
|
})
|
|
srv := httptest.NewServer(mux)
|
|
defer srv.Close()
|
|
|
|
s, err := Read(context.Background(), srv.URL, "test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(s.Pages) != 2 || !strings.Contains(s.PromptText(), "Title: Rival") {
|
|
t.Errorf("pages: %+v", s.Pages)
|
|
}
|
|
if strings.Join(s.Feeds, " ") != srv.URL+"/feed.xml https://rival.example/atom" {
|
|
t.Errorf("feeds: %q", s.Feeds)
|
|
}
|
|
for _, l := range s.Links {
|
|
if strings.HasPrefix(l, "mailto:") {
|
|
t.Errorf("mailto link kept: %s", l)
|
|
}
|
|
}
|
|
// The home page's own account comes first.
|
|
if a := FindAccounts(s.Links); a.X != "rivalhq" {
|
|
t.Errorf("x = %q (links %q)", a.X, s.Links)
|
|
}
|
|
}
|
|
|
|
func TestFindAccounts(t *testing.T) {
|
|
a := FindAccounts([]string{
|
|
"https://twitter.com/intent/tweet?text=hi",
|
|
"https://twitter.com/share",
|
|
"https://x.com/acme",
|
|
"https://www.linkedin.com/company/acme-inc/",
|
|
"https://www.youtube.com/channel/UCabcdefghijklmnopqrstuv",
|
|
"https://www.instagram.com/p/xyz",
|
|
"https://instagram.com/acme.co",
|
|
"https://www.reddit.com/r/selfhosted/",
|
|
"https://reddit.com/r/SelfHosted",
|
|
"https://old.reddit.com/r/homelab",
|
|
})
|
|
if a.X != "acme" || a.LinkedIn != "https://www.linkedin.com/company/acme-inc" ||
|
|
a.YouTubeChannel != "UCabcdefghijklmnopqrstuv" || a.Instagram != "acme.co" ||
|
|
strings.Join(a.Subreddits, ",") != "selfhosted,homelab" {
|
|
t.Errorf("accounts: %+v", a)
|
|
}
|
|
}
|
|
|
|
func TestNormalize(t *testing.T) {
|
|
if u, err := Normalize(" acme.example "); err != nil || u.String() != "https://acme.example" {
|
|
t.Errorf("got %v %v", u, err)
|
|
}
|
|
if _, err := Normalize("ftp://acme.example"); err == nil {
|
|
t.Error("ftp accepted")
|
|
}
|
|
}
|