Phase 10, part 7: posting accounts, and who may post to which
Social accounts become posting accounts: several per network, the company's and each person's own, with their tokens kept per account. The old sign-ins are adopted as the company's. Admins say who may post to which (Settings → Posting accounts); a draft can go out from one account or a copy to several, each recording who posted it and as what. Signing an account out, or removing its owner, holds the posts scheduled to it and tells whoever scheduled them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+18
-11
@@ -24,6 +24,7 @@ import (
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/mcpserver"
|
||||
"supermarket/internal/models"
|
||||
"supermarket/internal/posting"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/prospects"
|
||||
"supermarket/internal/secrets"
|
||||
@@ -430,39 +431,45 @@ func TestProfileDraftNeedsAI(t *testing.T) {
|
||||
|
||||
func TestLinkedInExpiryReminders(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
_ = s.Secrets.Set(map[string]string{secrets.LinkedInAccessToken: "tok", secrets.LinkedInAuthorURN: "urn:li:person:1"})
|
||||
day := 24 * time.Hour
|
||||
get := func(path string) string { return do(h, http.MethodGet, path, nil, nil).Body.String() }
|
||||
signIn := func(expires time.Time) {
|
||||
t.Helper()
|
||||
a := &posting.Account{Network: posting.LinkedIn, Name: "Pat", External: "urn:li:person:1", Expires: expires}
|
||||
if err := posting.Save(s.DB, s.Secrets, a, "tok", "", time.Now()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Plenty of time: the card says until when, no reminders.
|
||||
_ = s.saveConnection("linkedin", Connection{At: time.Now(), Expires: time.Now().Add(50 * day)})
|
||||
signIn(time.Now().Add(50 * day))
|
||||
if !strings.Contains(get("/settings/accounts"), "The sign-in lasts until") || strings.Contains(get("/"), "Reconnect LinkedIn") {
|
||||
t.Error("50 days left: wrong reminders")
|
||||
}
|
||||
if !s.connected()["linkedin"] {
|
||||
if !s.connected(localOwner)["linkedin"] {
|
||||
t.Error("50 days left: should be connected")
|
||||
}
|
||||
|
||||
// Saved before expiries were recorded, 50 days ago: 10 days left.
|
||||
_ = s.saveConnection("linkedin", Connection{At: time.Now().Add(-50 * day)})
|
||||
// 10 days left.
|
||||
signIn(time.Now().Add(10*day - time.Hour))
|
||||
for _, path := range []string{"/", "/posts"} {
|
||||
if body := get(path); !strings.Contains(body, "LinkedIn's sign-in expires in 9 days") && !strings.Contains(body, "LinkedIn's sign-in expires in 10 days") {
|
||||
t.Errorf("%s: no 10-day reminder", path)
|
||||
if body := get(path); !strings.Contains(body, "LinkedIn Pat's sign-in expires in 9 days") && !strings.Contains(body, "LinkedIn Pat's sign-in expires in 10 days") {
|
||||
t.Errorf("%s: no 10-day reminder: %s", path, body)
|
||||
}
|
||||
}
|
||||
|
||||
// Expired: reminders, not connected, and publishing says why.
|
||||
_ = s.saveConnection("linkedin", Connection{At: time.Now().Add(-61 * day), Expires: time.Now().Add(-day)})
|
||||
if body := get("/"); !strings.Contains(body, "LinkedIn's sign-in expired on") {
|
||||
signIn(time.Now().Add(-day))
|
||||
if body := get("/"); !strings.Contains(body, "LinkedIn Pat's sign-in expired on") {
|
||||
t.Error("expired: no reminder on the Overview")
|
||||
}
|
||||
if !strings.Contains(get("/settings/accounts"), "The sign-in expired on") {
|
||||
t.Error("expired: the card doesn't say so")
|
||||
}
|
||||
if s.connected()["linkedin"] {
|
||||
if s.connected(localOwner)["linkedin"] {
|
||||
t.Error("expired: still counted as connected")
|
||||
}
|
||||
if _, err := s.publishers()["linkedin"].Publish(context.Background(), content.Post{Text: "hi"}); err == nil ||
|
||||
if _, _, err := s.publishers().For(&content.Draft{Channel: content.ChannelLinkedIn}); err == nil ||
|
||||
!strings.Contains(err.Error(), "reconnect LinkedIn") {
|
||||
t.Errorf("expired publish: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user