From 39302564de1ff1937751cb5262aff7b4541eae68 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Mon, 26 Jan 2026 10:52:25 -0300 Subject: [PATCH] fix: skip publishing when social account is disconnected --- app/Jobs/PublishToSocialPlatform.php | 8 ++++ .../Jobs/PublishToSocialPlatformTest.php | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/app/Jobs/PublishToSocialPlatform.php b/app/Jobs/PublishToSocialPlatform.php index 319b1eff..e84a5ace 100644 --- a/app/Jobs/PublishToSocialPlatform.php +++ b/app/Jobs/PublishToSocialPlatform.php @@ -33,6 +33,14 @@ public function __construct(public PostPlatform $postPlatform) {} public function handle(): void { + if ($this->postPlatform->socialAccount->isDisconnected()) { + $this->postPlatform->markAsFailed('Social account is disconnected'); + $this->updatePostStatus(); + $this->broadcastStatus(); + + return; + } + $this->postPlatform->markAsPublishing(); $this->broadcastStatus(); diff --git a/tests/Feature/Jobs/PublishToSocialPlatformTest.php b/tests/Feature/Jobs/PublishToSocialPlatformTest.php index 189012ab..8c3319d9 100644 --- a/tests/Feature/Jobs/PublishToSocialPlatformTest.php +++ b/tests/Feature/Jobs/PublishToSocialPlatformTest.php @@ -156,3 +156,42 @@ $this->post->refresh(); expect($this->post->status)->toBe(PostStatus::Failed); }); + +test('publish to social platform skips publishing when account is disconnected', function () { + Event::fake(); + + $this->socialAccount->update([ + 'status' => AccountStatus::Disconnected, + 'disconnected_at' => now(), + ]); + + $publisher = Mockery::mock(LinkedInPublisher::class); + $publisher->shouldNotReceive('publish'); + + $this->app->instance(LinkedInPublisher::class, $publisher); + + (new PublishToSocialPlatform($this->postPlatform))->handle(); + + $this->postPlatform->refresh(); + expect($this->postPlatform->status)->toBe('failed'); + expect($this->postPlatform->error_message)->toBe('Social account is disconnected'); +}); + +test('publish to social platform skips publishing when account token is expired', function () { + Event::fake(); + + $this->socialAccount->update([ + 'status' => AccountStatus::TokenExpired, + ]); + + $publisher = Mockery::mock(LinkedInPublisher::class); + $publisher->shouldNotReceive('publish'); + + $this->app->instance(LinkedInPublisher::class, $publisher); + + (new PublishToSocialPlatform($this->postPlatform))->handle(); + + $this->postPlatform->refresh(); + expect($this->postPlatform->status)->toBe('failed'); + expect($this->postPlatform->error_message)->toBe('Social account is disconnected'); +});