Add a Publisher abstraction and queued job to publish from the UI

Introduce Publisher/PublisherManager (WordPress + Reddit implementations)
so publishing logic is shared between the CLI, the queue, and future
network integrations. Add a "Publish" button on the Posts page that
dispatches PublishPostJob instead of blocking the request — Reddit's
publisher shells out to the existing Playwright sidecar and can take
tens of seconds, so it can't run synchronously in a web request.

Adds a `target` field (e.g. subreddit) and `publishing` status to Post,
plus a `publish_error` field so failures surface in the UI. Refactors
posts:publish to delegate to WordPressPublisher without changing its
CLI output contract (existing tests pass unchanged).

Also fixes two bugs found along the way: UpdatePostRequest was silently
dropping `published_url` from PATCH requests (never in its validation
rules, despite AI_API.md documenting it), and three Livewire index-page
tests were broken by the earlier auth change (never re-run after adding
the `auth` middleware) since they hit routes via HTTP without a logged-in
user.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
m105
2026-07-21 14:04:45 +03:00
co-authored by Claude Sonnet 5
parent 0cf72b44b7
commit 9278d2e8a0
26 changed files with 735 additions and 76 deletions
+30 -1
View File
@@ -1,16 +1,20 @@
<?php
use App\Jobs\PublishPostJob;
use App\Livewire\Posts\Index;
use App\Models\Post;
use App\Models\Site;
use App\Models\SocialAccount;
use App\Models\User;
use Illuminate\Support\Facades\Queue;
use Livewire\Livewire;
test('posts index page lists existing posts', function () {
$site = Site::factory()->create(['name' => 'My Blog']);
Post::factory()->create(['site_id' => $site->id, 'title' => 'Hello World Post']);
$this->get(route('posts.index'))
$this->actingAs(User::factory()->create())
->get(route('posts.index'))
->assertOk()
->assertSee('Hello World Post')
->assertSee('My Blog');
@@ -79,3 +83,28 @@ test('a post can be deleted', function () {
expect(Post::find($post->id))->toBeNull();
});
test('publishing a post queues the job and marks it publishing', function () {
Queue::fake();
$site = Site::factory()->wordpress()->create();
$post = Post::factory()->create(['site_id' => $site->id, 'type' => 'blog', 'title' => 'Hi', 'status' => 'draft']);
Livewire::test(Index::class)->call('publish', $post->id);
expect($post->fresh()->status)->toBe('publishing');
Queue::assertPushed(PublishPostJob::class, fn ($job) => $job->postId === $post->id);
});
test('publishing a post with no available publisher shows a notice and does not queue anything', function () {
Queue::fake();
$post = Post::factory()->create(['type' => 'twitter', 'status' => 'draft']);
Livewire::test(Index::class)
->call('publish', $post->id)
->assertSee("No publisher available yet for post type 'twitter'");
expect($post->fresh()->status)->toBe('draft');
Queue::assertNotPushed(PublishPostJob::class);
});