Files
supermarket/internal/api/sitemap/sitemap_test.go
T
davidandClaude Opus 5.5 cd24f2a06d Phase 1, part 4: promote the company's own products
- Content lists the company first, at /content/own: its products from
  the profile (always there to pick from), its own feeds (a new profile
  field for the blog, news and releases), and new or updated pages from
  its websites' sitemaps, with each page's title and description.
- Drafts from it are kind "product" (utm_campaign=product), filed under
  the company's name, and prompted to promote the company's own work
  without unsupported claims; on Reddit, in the makers' voice, with a
  warning that self-promotion is often restricted.

This completes Phase 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 14:42:37 -07:00

62 lines
2.2 KiB
Go

package sitemap
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
func TestNewPages(t *testing.T) {
var srv *httptest.Server
srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/sitemap.xml":
w.Write([]byte(`<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>` + srv.URL + `/posts.xml</loc></sitemap><sitemap><loc>https://elsewhere.example/x.xml</loc></sitemap></sitemapindex>`))
case "/posts.xml":
w.Write([]byte(`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>` + srv.URL + `/new</loc><lastmod>2026-11-19</lastmod></url>
<url><loc>` + srv.URL + `/newer</loc><lastmod>2026-11-20T08:00:00+00:00</lastmod></url>
<url><loc>` + srv.URL + `/old</loc><lastmod>2026-01-01</lastmod></url>
<url><loc>` + srv.URL + `/undated</loc></url>
<url><loc>https://elsewhere.example/page</loc><lastmod>2026-11-20</lastmod></url>
</urlset>`))
case "/newer":
w.Write([]byte(`<html><head><title>Release 2.0 &amp; more</title>
<meta name="description" content="Faster sync."><meta property="og:description" content="ignored"></head></html>`))
default:
http.NotFound(w, r)
}
}))
defer srv.Close()
c := New("test")
pages, err := c.NewPages(context.Background(), srv.URL+"/blog/", time.Date(2026, 11, 1, 0, 0, 0, 0, time.UTC))
if err != nil {
t.Fatal(err)
}
if len(pages) != 2 || !strings.HasSuffix(pages[0].URL, "/newer") || !strings.HasSuffix(pages[1].URL, "/new") {
t.Fatalf("pages = %+v", pages)
}
it, err := c.Item(context.Background(), pages[0], "_own")
if err != nil {
t.Fatal(err)
}
if it.Title != "Release 2.0 & more" || it.Body != "Faster sync." || !strings.HasPrefix(it.ID, "page:") || it.AppName != "_own" {
t.Errorf("item = %+v", it)
}
if _, err := c.Item(context.Background(), pages[1], "_own"); err == nil {
t.Error("expected an error for a missing page")
}
}
func TestPageInfoOG(t *testing.T) {
title, desc := PageInfo(`<meta content='OG title' property='og:title'><meta property="og:description" content="OG desc">`)
if title != "OG title" || desc != "OG desc" {
t.Errorf("got %q, %q", title, desc)
}
}