From 0cd5e8f74423f0a4d07cb8497997c3351857a527 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Mon, 26 Jan 2026 16:01:14 -0300 Subject: [PATCH] fix: update scheduled_at to current time when publishing immediately When clicking "Publish Now", the scheduled_at was keeping the original scheduled time while published_at was set to the actual publish time. This caused confusion in the UI showing different dates. Now when status is 'publishing', scheduled_at is updated to now() before dispatching the PublishPost job. --- app/Http/Controllers/PostController.php | 1 + tests/Feature/PostControllerTest.php | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index 7cb80ccf..c8b14c64 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -262,6 +262,7 @@ public function update(UpdatePostRequest $request, Post $post): RedirectResponse // Dispatch publish job if publishing now if ($status === 'publishing') { + $post->update(['scheduled_at' => now()]); PublishPost::dispatch($post); session()->flash('flash.banner', __('posts.flash.publishing')); diff --git a/tests/Feature/PostControllerTest.php b/tests/Feature/PostControllerTest.php index ab6bc677..1bd90411 100644 --- a/tests/Feature/PostControllerTest.php +++ b/tests/Feature/PostControllerTest.php @@ -230,6 +230,39 @@ $response->assertRedirect(); }); +test('publish now updates scheduled_at to current time', function () { + $this->freezeTime(); + + $post = Post::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'user_id' => $this->user->id, + 'status' => PostStatus::Draft, + 'scheduled_at' => now()->addDays(7), + ]); + + $postPlatform = PostPlatform::factory()->create([ + 'post_id' => $post->id, + 'social_account_id' => $this->socialAccount->id, + 'content' => 'Test content', + ]); + + $response = $this->actingAs($this->user)->put(route('posts.update', $post), [ + 'status' => 'publishing', + 'platforms' => [ + [ + 'id' => $postPlatform->id, + 'content' => 'Test content', + 'content_type' => ContentType::LinkedInPost->value, + ], + ], + ]); + + $response->assertRedirect(); + + $post->refresh(); + expect($post->scheduled_at->toDateTimeString())->toBe(now()->toDateTimeString()); +}); + // Destroy tests test('destroy post requires authentication', function () { $post = Post::factory()->create([