test: cover credential-clearing and trailing-slash URL edge cases
Also fixes a missing trailing newline in SiteResource.php.
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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';
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user