Phase 1, part 1: fetch, write and publish posts from the web app
Brings back posting, which Phase 0 removed with the terminal interface. - Content page: per inventory entry, fetch its X account, X hashtag search, YouTube channel and RSS/Atom feeds (new), then select, dismiss or restore the fetched items, which are kept in the database. - Writing: one AI call returns a draft per channel (X and LinkedIn), prompted from the company profile, the entry's relationship, talking points and mention policy, and each channel's rules. Fetched text is quoted as untrusted. An over-long X draft gets one request to shorten. - Drafts page: edit with a live length counter that counts like X, then publish each draft on its own. A draft is claimed before posting so it can't go out twice; failures are kept on the draft for a retry; X tokens are refreshed and saved. - Migration 2 adds content_items and drafts, and turns queued posts into drafts for the platforms they hadn't reached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package rss
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseRSS(t *testing.T) {
|
||||
feed := `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<channel><title>Jitsi blog</title>
|
||||
<item><title>Jitsi 3 & more</title><link>https://jitsi.org/blog/3</link>
|
||||
<guid>jitsi-3</guid><pubDate>Mon, 02 Nov 2026 10:00:00 +0000</pubDate>
|
||||
<description><![CDATA[<p>New <b>release</b>.</p>]]></description><dc:creator>Saúl</dc:creator></item>
|
||||
<item><title>No date</title><link>https://jitsi.org/blog/x</link></item>
|
||||
</channel></rss>`
|
||||
items, err := Parse([]byte(feed), "Jitsi")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(items) != 2 {
|
||||
t.Fatalf("got %d items", len(items))
|
||||
}
|
||||
it := items[0]
|
||||
if it.Title != "Jitsi 3 & more" || it.Body != "New release ." || it.Author != "Saúl" || it.URL != "https://jitsi.org/blog/3" {
|
||||
t.Errorf("item = %+v", it)
|
||||
}
|
||||
if !it.PublishedAt.Equal(time.Date(2026, 11, 2, 10, 0, 0, 0, time.UTC)) {
|
||||
t.Errorf("date = %v", it.PublishedAt)
|
||||
}
|
||||
if !strings.HasPrefix(it.ID, "rss:") || it.ID == items[1].ID || it.AppName != "Jitsi" {
|
||||
t.Errorf("ids %q %q", it.ID, items[1].ID)
|
||||
}
|
||||
if !items[1].PublishedAt.IsZero() || items[1].Author != "Jitsi blog" {
|
||||
t.Errorf("undated item = %+v", items[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAtom(t *testing.T) {
|
||||
feed := `<feed xmlns="http://www.w3.org/2005/Atom"><title>Releases</title>
|
||||
<entry><title>v2.0</title><id>tag:x,2026:2</id>
|
||||
<link rel="alternate" href="https://example.com/v2"/><link rel="edit" href="https://example.com/edit"/>
|
||||
<updated>2026-11-03T08:00:00Z</updated><summary>Faster.</summary><author><name>Ana</name></author></entry>
|
||||
</feed>`
|
||||
items, err := Parse([]byte(feed), "X")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(items) != 1 || items[0].URL != "https://example.com/v2" || items[0].Body != "Faster." || items[0].Author != "Ana" {
|
||||
t.Fatalf("items = %+v", items)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRejectsHTML(t *testing.T) {
|
||||
if _, err := Parse([]byte(`<html><body>hi</body></html>`), "X"); err == nil {
|
||||
t.Fatal("expected an error for an HTML page")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user