fix: skip publishing when social account is disconnected

This commit is contained in:
Paulo Castellano 2026-01-26 10:52:25 -03:00
parent e1ac9f87f8
commit 39302564de
2 changed files with 47 additions and 0 deletions

View file

@ -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();

View file

@ -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');
});