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.
This commit is contained in:
parent
5f5dd0c7e7
commit
0cd5e8f744
2 changed files with 34 additions and 0 deletions
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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([
|
||||
|
|
|
|||
Loading…
Reference in a new issue