Phase 6 part 4: post as the LinkedIn company page
A second LinkedIn app (Community Management API) with its own sign-in on Settings → Social accounts: the pages the member may post for are listed and one chosen, new LinkedIn drafts default to the page or to you, and each draft can switch before it's published. Schema 25. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -82,9 +82,11 @@ func TestItems(t *testing.T) {
|
||||
type fakePub struct {
|
||||
calls []string
|
||||
err error
|
||||
got Post // the last post
|
||||
}
|
||||
|
||||
func (f *fakePub) Publish(_ context.Context, p Post) (string, error) {
|
||||
f.got = p
|
||||
call := p.Text + "|" + p.SourceURL
|
||||
if p.Target != "" {
|
||||
call = "r/" + p.Target + "|" + p.Title + "|" + call
|
||||
@@ -366,3 +368,61 @@ func TestDraftsForSignal(t *testing.T) {
|
||||
t.Errorf("prompt lacks the signal: %s", prompt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinkedInAuthor(t *testing.T) {
|
||||
d := openDB(t)
|
||||
ctx := context.Background()
|
||||
mk := func() (li, x Draft) {
|
||||
if _, err := CreateDrafts(d, []Draft{{Channel: ChannelLinkedIn, Content: "Hello LinkedIn"}, {Channel: ChannelX, Content: "Hello X"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ds, _ := ListDrafts(d, 2, StatusDraft)
|
||||
for _, dr := range ds {
|
||||
if dr.Channel == ChannelLinkedIn {
|
||||
li = dr
|
||||
} else {
|
||||
x = dr
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
li, x := mk()
|
||||
if li.LinkedInAs != "" || x.LinkedInAs != "" {
|
||||
t.Errorf("default: %q %q", li.LinkedInAs, x.LinkedInAs)
|
||||
}
|
||||
// With the page as the default, new LinkedIn drafts post as it; X's don't change.
|
||||
d.PutJSON(LinkedInDefaultKey, AsPage)
|
||||
DiscardDraft(d, li.ID)
|
||||
DiscardDraft(d, x.ID)
|
||||
li, x = mk()
|
||||
if li.LinkedInAs != AsPage || x.LinkedInAs != "" {
|
||||
t.Errorf("page default: %q %q", li.LinkedInAs, x.LinkedInAs)
|
||||
}
|
||||
if err := SetLinkedInAs(d, x.ID, AsPage); err == nil {
|
||||
t.Error("an X draft took a LinkedIn author")
|
||||
}
|
||||
if err := SetLinkedInAs(d, li.ID, "someone"); err == nil {
|
||||
t.Error("an unknown author was taken")
|
||||
}
|
||||
pub := &fakePub{}
|
||||
if _, err := Publish(ctx, d, Publishers{ChannelLinkedIn: pub}, nil, li.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !pub.got.AsPage {
|
||||
t.Errorf("published as: %+v", pub.got)
|
||||
}
|
||||
// Switched back to you before publishing.
|
||||
_, _ = mk()
|
||||
ds, _ := ListDrafts(d, 5, StatusDraft)
|
||||
for _, dr := range ds {
|
||||
if dr.Channel == ChannelLinkedIn {
|
||||
if err := SetLinkedInAs(d, dr.ID, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Publish(ctx, d, Publishers{ChannelLinkedIn: pub}, nil, dr.ID)
|
||||
}
|
||||
}
|
||||
if pub.got.AsPage {
|
||||
t.Error("published as the page after switching")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user