Phase 1, part 2: Inbox, scheduled publishing and UTM tags
- Inbox: a top-level page, with a count in the menu, for everything waiting for approval; Content's drafts are reviewed there. /drafts redirects to it. - Scheduling: publish a draft now or at a time (migration 3 adds publish_at). A scheduler in the app publishes due drafts every 30 seconds. Posts more than 12 hours overdue, or refused before posting, go back to the Inbox with the reason. Content gets Scheduled and Published tabs. - UTM tags on links to the company's own websites and product pages, added when publishing; drafts stay untagged. - The container runs in the computer's time zone, so times are shown and read correctly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -89,11 +90,15 @@ func TestDraftsPage(t *testing.T) {
|
||||
ids[d.Channel] = strconv.FormatInt(d.ID, 10)
|
||||
}
|
||||
|
||||
rec := do(h, http.MethodGet, "/drafts", nil, nil)
|
||||
if rec := do(h, http.MethodGet, "/drafts?msg=drafted", nil, nil); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/inbox?msg=drafted" {
|
||||
t.Errorf("old drafts page: %d %s", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
rec := do(h, http.MethodGet, "/inbox", nil, nil)
|
||||
body := rec.Body.String()
|
||||
if rec.Code != 200 || strings.Index(body, "X text") > strings.Index(body, "LinkedIn text") ||
|
||||
!strings.Contains(body, "31 / 280 including the link") || !strings.Contains(body, `data-reserve="25"`) {
|
||||
t.Errorf("drafts page (X should come first):\n%s", body)
|
||||
!strings.Contains(body, "31 / 280 including the link") || !strings.Contains(body, `data-reserve="25"`) ||
|
||||
!strings.Contains(body, `class="count-badge">2<`) {
|
||||
t.Errorf("inbox (X should come first, menu count 2):\n%s", body)
|
||||
}
|
||||
|
||||
// Save an edit.
|
||||
@@ -123,6 +128,71 @@ func TestDraftsPage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestScheduleFromInbox(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
if _, err := content.CreateDrafts(s.DB, []content.Draft{{InventoryName: "Jitsi", Kind: "partner", Channel: content.ChannelX, Content: "Soon"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
drafts, _ := content.ListDrafts(s.DB, 1, content.StatusDraft)
|
||||
id := strconv.FormatInt(drafts[0].ID, 10)
|
||||
|
||||
// A past time, or none, is refused.
|
||||
past := time.Now().Add(-time.Hour).Format(dateTimeLocal)
|
||||
if rec := postForm(h, "/drafts/"+id+"/schedule", url.Values{"when": {past}}); !strings.Contains(rec.Body.String(), "that time has passed") {
|
||||
t.Errorf("past time: %s", rec.Body.String())
|
||||
}
|
||||
if rec := postForm(h, "/drafts/"+id+"/schedule", url.Values{"when": {""}}); !strings.Contains(rec.Body.String(), "choose a date") {
|
||||
t.Errorf("no time: %s", rec.Body.String())
|
||||
}
|
||||
|
||||
when := time.Now().Add(2 * time.Hour).Truncate(time.Minute)
|
||||
rec := postForm(h, "/drafts/"+id+"/schedule", url.Values{"content": {"Soon, edited"}, "when": {when.Format(dateTimeLocal)}})
|
||||
if rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("schedule: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
d, _ := content.GetDraft(s.DB, mustID(id))
|
||||
if d.Status != content.StatusScheduled || !d.PublishAt.Equal(when) || d.Content != "Soon, edited" {
|
||||
t.Errorf("scheduled draft: %+v (want %v)", d, when)
|
||||
}
|
||||
body := do(h, http.MethodGet, "/content/scheduled", nil, nil).Body.String()
|
||||
if !strings.Contains(body, "Soon, edited") || !strings.Contains(body, when.Format("15:04")) || !strings.Contains(body, "not connected") {
|
||||
t.Errorf("scheduled page:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(do(h, http.MethodGet, "/inbox", nil, nil).Body.String(), "Nothing waiting") {
|
||||
t.Error("a scheduled draft is still in the Inbox")
|
||||
}
|
||||
|
||||
// When it's due and X isn't connected, it goes back to the Inbox with
|
||||
// the reason instead of being retried for ever.
|
||||
s.publishDue(context.Background(), when.Add(time.Minute))
|
||||
d, _ = content.GetDraft(s.DB, mustID(id))
|
||||
if d.Status != content.StatusFailed || !strings.Contains(d.Error, "isn't connected") {
|
||||
t.Errorf("after the scheduler: %+v", d)
|
||||
}
|
||||
|
||||
// Unschedule from the Scheduled page.
|
||||
_ = content.Schedule(s.DB, mustID(id), when)
|
||||
if rec := postForm(h, "/drafts/"+id+"/unschedule", url.Values{"from": {"scheduled"}}); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("unschedule: %d", rec.Code)
|
||||
}
|
||||
if d, _ := content.GetDraft(s.DB, mustID(id)); d.Status != content.StatusDraft {
|
||||
t.Errorf("unscheduled: %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaggerFromProfile(t *testing.T) {
|
||||
s, _ := newTestServer(t, nil)
|
||||
if s.tagger() != nil {
|
||||
t.Error("no sites in the profile: no tagger")
|
||||
}
|
||||
_ = profile.Save(s.DB, &profile.Profile{Name: "Acme", Description: "x",
|
||||
Websites: []profile.Website{{URL: "https://acme.example"}}, Products: []profile.Product{{Name: "P", URL: "https://app.acme.dev/p"}}})
|
||||
tg := s.tagger()
|
||||
if tg == nil || !tg.Own("https://acme.example/blog") || !tg.Own("https://app.acme.dev/") || tg.Own("https://jitsi.org") {
|
||||
t.Errorf("tagger: %+v", tg)
|
||||
}
|
||||
}
|
||||
|
||||
func mustID(s string) int64 {
|
||||
n, _ := strconv.ParseInt(s, 10, 64)
|
||||
return n
|
||||
|
||||
Reference in New Issue
Block a user