Files
m105andClaude Sonnet 5 9278d2e8a0 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>
2026-07-21 14:04:45 +03:00

53 lines
1.4 KiB
PHP

<?php
use App\Livewire\Auth\Login;
use App\Models\User;
use Livewire\Livewire;
test('guests are redirected to login when visiting a protected page', function () {
$this->get(route('sites.index'))
->assertRedirect(route('login'));
});
test('the api stays open to guests', function () {
$this->getJson('/api/sites')->assertOk();
});
test('users can log in with correct credentials', function () {
$user = User::factory()->create(['password' => bcrypt('correct-password')]);
Livewire::test(Login::class)
->set('email', $user->email)
->set('password', 'correct-password')
->call('login')
->assertRedirect(route('sites.index'));
$this->assertAuthenticatedAs($user);
});
test('users cannot log in with incorrect credentials', function () {
$user = User::factory()->create(['password' => bcrypt('correct-password')]);
Livewire::test(Login::class)
->set('email', $user->email)
->set('password', 'wrong-password')
->call('login')
->assertHasErrors('email');
$this->assertGuest();
});
test('authenticated users are redirected away from the login page', function () {
$this->actingAs(User::factory()->create())
->get(route('login'))
->assertRedirect();
});
test('users can log out', function () {
$this->actingAs(User::factory()->create())
->post(route('logout'))
->assertRedirect('/login');
$this->assertGuest();
});