LinkedIn: - The API version was fixed at 202501, retired by LinkedIn (426 NONEXISTENT_VERSION). It's now the month before last, stepping back a month (up to four) if LinkedIn says a version isn't active. - The versioned Posts API needs a title for a link's article card (422). Supermarket reads the linked page's title and description and sends them, falling back to the page's address as the title. Tested for real: a post with a link went out to the member's profile. Inbox is now Posts: the menu, page, messages and docs; the page moves to /posts, and /inbox redirects there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
3.2 KiB
Go
95 lines
3.2 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")
|
|
}
|
|
}
|
|
|
|
func TestPageInfo(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
w.Write([]byte(`<head><title>Widget 2 & more</title><meta name="description" content="Faster widgets."></head>`))
|
|
}))
|
|
defer srv.Close()
|
|
title, desc, err := PageInfo(context.Background(), srv.URL+"/w", "test")
|
|
if err != nil || title != "Widget 2 & more" || desc != "Faster widgets." {
|
|
t.Errorf("got %q %q %v", title, desc, err)
|
|
}
|
|
}
|