vito/tests/Feature/RedirectsTest.php
Jamie Wood f483f7fdca
Add site redirects (#552)
* feat(redirects): add redirects to sites

* chore(style): fixed coding style issues

* style: fix php-stan docblocks

* style: pint cleanup

* tests: fixed redirect test suite

* feat: vhosts include additional configs

* fix: use exact location matching

* - add enums
- use queues
- use vhost rather than separate conf files
- vhost formatter
- cleanup

* generate docs

---------

Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
2025-03-31 17:30:57 +02:00

83 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Enums\RedirectStatus;
use App\Facades\SSH;
use App\Models\Redirect;
use App\Web\Pages\Servers\Sites\Pages\Redirects\Index;
use App\Web\Pages\Servers\Sites\Pages\Redirects\Widgets\RedirectsList;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class RedirectsTest extends TestCase
{
use RefreshDatabase;
public function test_see_redirects(): void
{
$this->actingAs($this->user);
$redirect = Redirect::factory()->create([
'site_id' => $this->site->id,
]);
$this->get(
Index::getUrl([
'server' => $this->server,
'site' => $this->site,
])
)
->assertSuccessful()
->assertSee($redirect->from);
}
public function test_delete_redirect(): void
{
SSH::fake();
$this->actingAs($this->user);
$redirect = Redirect::factory()->create([
'site_id' => $this->site->id,
]);
Livewire::test(RedirectsList::class, [
'server' => $this->server,
'site' => $this->site,
])
->callTableAction('delete', $redirect->id)
->assertSuccessful();
$this->assertDatabaseMissing('redirects', [
'id' => $redirect->id,
]);
}
public function test_create_redirect(): void
{
SSH::fake();
$this->actingAs($this->user);
Livewire::test(Index::class, [
'server' => $this->server,
'site' => $this->site,
])
->callAction('create', [
'from' => 'some-path',
'to' => 'https://example.com/redirect',
'mode' => 301,
])
->assertSuccessful();
$this->assertDatabaseHas('redirects', [
'from' => 'some-path',
'to' => 'https://example.com/redirect',
'mode' => 301,
'status' => RedirectStatus::READY,
]);
}
}