For custom sites we'll post to via their own API — there's no wired-in publisher for these, so this is where the site owner documents how to actually post there (auth, endpoints, payload shape). Shown in the UI for non-WordPress sites, exposed via the JSON API, and pointed to from AI_API.md's "any other network/CMS" fallback section so an agent checks it before improvising. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
145 lines
4.5 KiB
PHP
145 lines
4.5 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Sites\Index;
|
|
use App\Models\Site;
|
|
use App\Models\User;
|
|
use Livewire\Livewire;
|
|
|
|
test('sites index page lists existing sites', function () {
|
|
$site = Site::factory()->create(['name' => 'Example Site']);
|
|
|
|
$this->actingAs(User::factory()->create())
|
|
->get(route('sites.index'))
|
|
->assertOk()
|
|
->assertSee('Example Site');
|
|
});
|
|
|
|
test('a new site can be created', function () {
|
|
Livewire::test(Index::class)
|
|
->set('name', 'New Site')
|
|
->set('url', 'https://newsite.test')
|
|
->set('description', 'Some description')
|
|
->call('save');
|
|
|
|
expect(Site::where('name', 'New Site')->exists())->toBeTrue();
|
|
});
|
|
|
|
test('name and url are required to create a site', function () {
|
|
Livewire::test(Index::class)
|
|
->set('name', '')
|
|
->set('url', '')
|
|
->call('save')
|
|
->assertHasErrors(['name', 'url']);
|
|
});
|
|
|
|
test('an existing site can be edited', function () {
|
|
$site = Site::factory()->create(['name' => 'Old Name']);
|
|
|
|
Livewire::test(Index::class)
|
|
->call('edit', $site->id)
|
|
->set('name', 'Updated Name')
|
|
->call('save');
|
|
|
|
expect($site->fresh()->name)->toBe('Updated Name');
|
|
});
|
|
|
|
test('a site can be deleted', function () {
|
|
$site = Site::factory()->create();
|
|
|
|
Livewire::test(Index::class)->call('delete', $site->id);
|
|
|
|
expect(Site::find($site->id))->toBeNull();
|
|
});
|
|
|
|
test('a new WordPress site can be created with credentials', function () {
|
|
Livewire::test(Index::class)
|
|
->set('name', 'WP Site')
|
|
->set('url', 'https://wp.example.com')
|
|
->set('cmsType', 'wordpress')
|
|
->set('wpUsername', 'admin')
|
|
->set('wpAppPassword', 'abcd 1234 efgh 5678')
|
|
->call('save');
|
|
|
|
$site = Site::where('name', 'WP Site')->first();
|
|
|
|
expect($site)
|
|
->cms_type->toBe('wordpress')
|
|
->wp_username->toBe('admin')
|
|
->wp_app_password->toBe('abcd 1234 efgh 5678');
|
|
});
|
|
|
|
test('WordPress username and app password are required together when cms_type is wordpress', function () {
|
|
Livewire::test(Index::class)
|
|
->set('name', 'WP Site')
|
|
->set('url', 'https://wp.example.com')
|
|
->set('cmsType', 'wordpress')
|
|
->set('wpUsername', '')
|
|
->set('wpAppPassword', '')
|
|
->call('save')
|
|
->assertHasErrors(['wpUsername', 'wpAppPassword']);
|
|
});
|
|
|
|
test('a site defaults to custom cms_type with no WordPress fields required', function () {
|
|
Livewire::test(Index::class)
|
|
->set('name', 'Plain Site')
|
|
->set('url', 'https://plain.example.com')
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
expect(Site::where('name', 'Plain Site')->first()->cms_type)->toBe('custom');
|
|
});
|
|
|
|
test('editing a site loads its WordPress fields', function () {
|
|
$site = Site::factory()->wordpress()->create(['wp_username' => 'editor']);
|
|
|
|
Livewire::test(Index::class)
|
|
->call('edit', $site->id)
|
|
->assertSet('cmsType', 'wordpress')
|
|
->assertSet('wpUsername', 'editor');
|
|
});
|
|
|
|
test('WordPress app password can be revealed and hidden in the table', function () {
|
|
$site = Site::factory()->wordpress()->create();
|
|
|
|
Livewire::test(Index::class)
|
|
->call('toggleReveal', $site->id)
|
|
->assertSet('revealedId', $site->id)
|
|
->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();
|
|
});
|
|
|
|
test('a custom site can be created with api_instructions', function () {
|
|
Livewire::test(Index::class)
|
|
->set('name', 'Custom Site')
|
|
->set('url', 'https://custom.example.com')
|
|
->set('cmsType', 'custom')
|
|
->set('apiInstructions', 'POST to /api/publish with a bearer token from .env')
|
|
->call('save');
|
|
|
|
$site = Site::where('name', 'Custom Site')->first();
|
|
|
|
expect($site->api_instructions)->toBe('POST to /api/publish with a bearer token from .env');
|
|
});
|
|
|
|
test('editing a site loads its api_instructions', function () {
|
|
$site = Site::factory()->create(['cms_type' => 'custom', 'api_instructions' => 'Use the /publish endpoint']);
|
|
|
|
Livewire::test(Index::class)
|
|
->call('edit', $site->id)
|
|
->assertSet('apiInstructions', 'Use the /publish endpoint');
|
|
});
|