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([