Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
test(linkedin): end-to-end document publish + harden title resolution
Paulo Castellano051c797cc1eb
diff --git a/app/Services/Social/LinkedInPagePublisher.php b/app/Services/Social/LinkedInPagePublisher.phpindex 9adb038c1..7df6d1d4d 100644--- a/app/Services/Social/LinkedInPagePublisher.php+++ b/app/Services/Social/LinkedInPagePublisher.php@@ -233,7 +233,7 @@ class LinkedInPagePublisherreturn (string) $title;}- return $postPlatform->post->mediaItems->first()?->original_filename ?? 'Document';+ return $postPlatform->post->mediaItems->first(fn ($media) => $media->isDocument())?->original_filename ?? 'Document';}private function publishDocument(string $organizationUrn, ?string $content, $mediaCollection, string $title, $account): arraydiff --git a/app/Services/Social/LinkedInPublisher.php b/app/Services/Social/LinkedInPublisher.phpindex dee69839c..1e120948a 100644--- a/app/Services/Social/LinkedInPublisher.php+++ b/app/Services/Social/LinkedInPublisher.php@@ -215,7 +215,7 @@ class LinkedInPublisherreturn (string) $title;}- return $postPlatform->post->mediaItems->first()?->original_filename ?? 'Document';+ return $postPlatform->post->mediaItems->first(fn ($media) => $media->isDocument())?->original_filename ?? 'Document';}private function publishDocument(string $personUrn, ?string $content, $mediaCollection, string $title): arraydiff --git a/tests/Feature/Jobs/PublishToSocialPlatformTest.php b/tests/Feature/Jobs/PublishToSocialPlatformTest.phpindex 92abd65a1..31c96aff4 100644--- a/tests/Feature/Jobs/PublishToSocialPlatformTest.php+++ b/tests/Feature/Jobs/PublishToSocialPlatformTest.php@@ -3,6 +3,7 @@declare(strict_types=1);use App\Enums\Post\Status as PostStatus;+use App\Enums\PostPlatform\ContentType;use App\Enums\PostPlatform\Status as PlatformStatus;use App\Enums\SocialAccount\Status as AccountStatus;use App\Enums\UserWorkspace\Role;@@ -23,6 +24,7 @@ use App\Services\Social\LinkedInPublisher;use Carbon\Carbon;use Illuminate\Support\Facades\Bus;use Illuminate\Support\Facades\Event;+use Illuminate\Support\Facades\Http;use Illuminate\Support\Facades\Mail;use Illuminate\Support\Facades\Queue;@@ -79,6 +81,61 @@ test('publish to social platform marks platform as published on success', functiexpect($this->postPlatform->platform_url)->toBe('https://linkedin.com/post/123');});+test('publish job runs the real document flow end-to-end for a LinkedIn PDF post', function () {+ Event::fake();++ // Real publisher (no mock) — exercise the full job -> getPublisher -> publishDocument chain.+ $this->socialAccount->update([+ 'platform_user_id' => 'person-xyz',+ 'token_expires_at' => now()->addDays(60),+ ]);+ $this->postPlatform->update(['content_type' => ContentType::LinkedInDocument]);+ $this->post->update([+ 'content' => 'Our deck',+ 'media' => [[+ 'id' => 'doc-1', 'path' => 'media/deck.pdf', 'url' => 'https://example.com/deck.pdf',+ 'type' => 'document', 'mime_type' => 'application/pdf', 'original_filename' => 'deck.pdf',+ ]],+ ]);++ $uploadUrl = 'https://www.linkedin.com/dms-uploads/document/e2e';++ Http::fake(function ($request) use ($uploadUrl) {+ $url = $request->url();++ if (str_contains($url, '/rest/documents') && str_contains($url, 'initializeUpload')) {+ return Http::response(['value' => ['uploadUrl' => $uploadUrl, 'document' => 'urn:li:document:E2E']], 200);+ }++ if ($url === $uploadUrl) {+ return Http::response(null, 201);+ }++ if (str_contains($url, '/rest/documents/')) {+ return Http::response(['status' => 'AVAILABLE'], 200);+ }++ if (str_contains($url, '/rest/posts')) {+ return Http::response(null, 201, ['x-restli-id' => 'urn:li:share:e2e']);+ }++ return Http::response('fake-pdf-bytes', 200);+ });++ (new PublishToSocialPlatform($this->postPlatform))->handle();++ $this->postPlatform->refresh();+ expect($this->postPlatform->status)->toBe(PlatformStatus::Published);+ expect($this->postPlatform->platform_post_id)->toBe('urn:li:share:e2e');++ Http::assertSent(fn ($request) => str_contains($request->url(), '/rest/documents') && str_contains($request->url(), 'initializeUpload'));+ Http::assertSent(function ($request) {+ return str_contains($request->url(), '/rest/posts')+ && data_get($request->data(), 'content.media.id') === 'urn:li:document:E2E'+ && data_get($request->data(), 'content.media.title') === 'deck.pdf';+ });+});+test('publish to social platform marks platform as failed on error', function () {Event::fake();