mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-22 03:02:20 +00:00
* SyncDatabases * Collation on Create inc WordPress * Refactored Enum * Resolve sync issue * Fix for PostgreSQL * pint * reversed enum * style adjustments * add unit tests * style * fix tests * more tests --------- Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com> Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
96 lines
2.6 KiB
PHP
96 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\API;
|
|
|
|
use App\Enums\DatabaseStatus;
|
|
use App\Facades\SSH;
|
|
use App\Models\Database;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class DatabaseTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_create_database(): void
|
|
{
|
|
Sanctum::actingAs($this->user, ['read', 'write']);
|
|
|
|
SSH::fake();
|
|
|
|
$this->json('POST', route('api.projects.servers.databases.create', [
|
|
'project' => $this->server->project,
|
|
'server' => $this->server,
|
|
]), [
|
|
'name' => 'database',
|
|
'charset' => 'utf8mb4',
|
|
'collation' => 'utf8mb4_unicode_ci',
|
|
])
|
|
->assertSuccessful()
|
|
->assertJsonFragment([
|
|
'name' => 'database',
|
|
'status' => DatabaseStatus::READY,
|
|
]);
|
|
}
|
|
|
|
public function test_show_database(): void
|
|
{
|
|
Sanctum::actingAs($this->user, ['read', 'write']);
|
|
|
|
/** @var Database $database */
|
|
$database = Database::factory()->create([
|
|
'server_id' => $this->server,
|
|
]);
|
|
|
|
$this->json('GET', route('api.projects.servers.databases.show', [
|
|
'project' => $this->server->project,
|
|
'server' => $this->server,
|
|
'database' => $database,
|
|
]))
|
|
->assertSuccessful()
|
|
->assertJsonFragment([
|
|
'name' => $database->name,
|
|
]);
|
|
}
|
|
|
|
public function test_see_databases_list(): void
|
|
{
|
|
Sanctum::actingAs($this->user, ['read', 'write']);
|
|
|
|
/** @var Database $database */
|
|
$database = Database::factory()->create([
|
|
'server_id' => $this->server,
|
|
]);
|
|
|
|
$this->json('GET', route('api.projects.servers.databases', [
|
|
'project' => $this->server->project,
|
|
'server' => $this->server,
|
|
]))
|
|
->assertSuccessful()
|
|
->assertJsonFragment([
|
|
'name' => $database->name,
|
|
]);
|
|
}
|
|
|
|
public function test_delete_database(): void
|
|
{
|
|
Sanctum::actingAs($this->user, ['read', 'write']);
|
|
|
|
SSH::fake();
|
|
|
|
/** @var Database $database */
|
|
$database = Database::factory()->create([
|
|
'server_id' => $this->server,
|
|
]);
|
|
|
|
$this->json('DELETE', route('api.projects.servers.databases.delete', [
|
|
'project' => $this->server->project,
|
|
'server' => $this->server,
|
|
'database' => $database,
|
|
]))
|
|
->assertSuccessful()
|
|
->assertNoContent();
|
|
}
|
|
}
|