Remind before LinkedIn's sign-in expires, and stop posting once it has

LinkedIn tokens last 60 days and can't be renewed without signing in
again. The expiry LinkedIn reports is now recorded (60 days from sign-in
for older connections). The LinkedIn card says until when; from two
weeks before, the Overview, the Inbox and the card remind you, with a
Reconnect button. Once expired, LinkedIn counts as not connected, due
posts come back to the Inbox saying why, and a 401 from LinkedIn reads
"reconnect LinkedIn" instead of the raw error.

Also fixes a leftover "Settings → Credentials" in a publish error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 11:43:59 -07:00
co-authored by Claude Opus 5.5
parent a2c8889599
commit 9c62680927
14 changed files with 159 additions and 9 deletions
+41
View File
@@ -2,6 +2,7 @@ package web
import (
"bytes"
"context"
"encoding/json"
"io"
"log/slog"
@@ -403,3 +404,43 @@ func TestProfileDraftNeedsAI(t *testing.T) {
t.Error("warning shown with an AI key saved")
}
}
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() }
// Plenty of time: the card says until when, no reminders.
_ = s.saveConnection("linkedin", Connection{At: time.Now(), Expires: 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"] {
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)})
for _, path := range []string{"/", "/inbox"} {
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)
}
}
// 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") {
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"] {
t.Error("expired: still counted as connected")
}
if _, err := s.publishers()["linkedin"].Publish(context.Background(), content.Post{Text: "hi"}); err == nil ||
!strings.Contains(err.Error(), "reconnect LinkedIn") {
t.Errorf("expired publish: %v", err)
}
}