From f7b71684f1c95040df356c84c34edad56f3e7f4f Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sun, 19 Jul 2026 17:05:01 +0300 Subject: [PATCH] test: cover credential-clearing and trailing-slash URL edge cases Also fixes a missing trailing newline in SiteResource.php. --- app/Http/Resources/SiteResource.php | 2 +- tests/Feature/Livewire/SitesTest.php | 14 +++++++++++++ tests/Feature/PublishPostCommandTest.php | 25 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/Http/Resources/SiteResource.php b/app/Http/Resources/SiteResource.php index a59131d..049823e 100644 --- a/app/Http/Resources/SiteResource.php +++ b/app/Http/Resources/SiteResource.php @@ -21,4 +21,4 @@ class SiteResource extends JsonResource 'updated_at' => $this->updated_at, ]; } -} \ No newline at end of file +} diff --git a/tests/Feature/Livewire/SitesTest.php b/tests/Feature/Livewire/SitesTest.php index 3d48b8f..373a18d 100644 --- a/tests/Feature/Livewire/SitesTest.php +++ b/tests/Feature/Livewire/SitesTest.php @@ -105,3 +105,17 @@ test('WordPress app password can be revealed and hidden in the table', function ->call('toggleReveal', $site->id) ->assertSet('revealedId', null); }); + +test('switching a WordPress site to a non-WordPress cms_type clears its credentials', function () { + $site = Site::factory()->wordpress()->create(['wp_username' => 'admin']); + + Livewire::test(Index::class) + ->call('edit', $site->id) + ->set('cmsType', 'custom') + ->call('save'); + + expect($site->fresh()) + ->cms_type->toBe('custom') + ->wp_username->toBeNull() + ->wp_app_password->toBeNull(); +}); diff --git a/tests/Feature/PublishPostCommandTest.php b/tests/Feature/PublishPostCommandTest.php index 8a20f1f..f1ed47f 100644 --- a/tests/Feature/PublishPostCommandTest.php +++ b/tests/Feature/PublishPostCommandTest.php @@ -112,3 +112,28 @@ test('it marks the post as failed when the site is unreachable', function () { expect($post->fresh()->status)->toBe('failed'); }); + +test('it correctly builds the WordPress endpoint URL when the site URL has a trailing slash', function () { + Http::fake([ + '*/wp-json/wp/v2/posts' => Http::response([ + 'id' => 42, + 'link' => 'https://wp.example.com/2026/07/hello-world/', + ], 201), + ]); + + $site = Site::factory()->wordpress()->create(['url' => 'https://wp.example.com/']); + $post = Post::factory()->create([ + 'site_id' => $site->id, + 'type' => 'blog', + 'title' => 'Hello World', + 'body' => 'Post content', + 'status' => 'draft', + ]); + + $this->artisan('posts:publish', ['post' => $post->id]) + ->assertExitCode(0); + + Http::assertSent(function ($request) { + return $request->url() === 'https://wp.example.com/wp-json/wp/v2/posts'; + }); +});