mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 08:52:35 +00:00
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>
This commit is contained in:
82
tests/Feature/API/RedirectsTest.php
Normal file
82
tests/Feature/API/RedirectsTest.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\API;
|
||||
|
||||
use App\Enums\RedirectStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Redirect;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RedirectsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_redirect(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
Sanctum::actingAs($this->user, ['read', 'write']);
|
||||
|
||||
$this->json('POST', route('api.projects.servers.sites.redirects.create', [
|
||||
'project' => $this->server->project,
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]), [
|
||||
'from' => 'testing/path',
|
||||
'to' => 'https://example.com',
|
||||
'mode' => 301,
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertJsonFragment([
|
||||
'from' => 'testing/path',
|
||||
'to' => 'https://example.com',
|
||||
'mode' => 301,
|
||||
'status' => RedirectStatus::READY,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_redirects_list(): void
|
||||
{
|
||||
Sanctum::actingAs($this->user, ['read']);
|
||||
|
||||
/** @var Redirect $redirect */
|
||||
$redirect = Redirect::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
|
||||
$this->json('GET', route('api.projects.servers.sites.redirects.index', [
|
||||
'project' => $this->server->project,
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]))
|
||||
->assertSuccessful()
|
||||
->assertJsonFragment([
|
||||
'from' => $redirect->from,
|
||||
'to' => $redirect->to,
|
||||
'mode' => $redirect->mode,
|
||||
'status' => $redirect->status,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_redirect(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
Sanctum::actingAs($this->user, ['write']);
|
||||
|
||||
$this->json('DELETE', route('api.projects.servers.sites.redirects.delete', [
|
||||
'project' => $this->server->project,
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
'redirect' => $this->redirect->id,
|
||||
]))
|
||||
->assertSuccessful()
|
||||
->assertNoContent();
|
||||
|
||||
$this->assertDatabaseMissing('redirects', [
|
||||
'id' => $this->redirect->id,
|
||||
]);
|
||||
}
|
||||
}
|
82
tests/Feature/RedirectsTest.php
Normal file
82
tests/Feature/RedirectsTest.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
use App\Enums\UserRole;
|
||||
use App\Enums\Webserver;
|
||||
use App\Models\NotificationChannel;
|
||||
use App\Models\Redirect;
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\SourceControl;
|
||||
@ -24,6 +25,8 @@ abstract class TestCase extends BaseTestCase
|
||||
|
||||
protected Site $site;
|
||||
|
||||
protected Redirect $redirect;
|
||||
|
||||
protected NotificationChannel $notificationChannel;
|
||||
|
||||
public const EXPECT_SUCCESS = true;
|
||||
@ -108,6 +111,10 @@ private function setupSite(): void
|
||||
'web_directory' => 'public',
|
||||
'branch' => 'main',
|
||||
]);
|
||||
|
||||
$this->redirect = Redirect::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
}
|
||||
|
||||
private function setupKeys(): void
|
||||
|
Reference in New Issue
Block a user