vito/tests/Feature/NodeJSTest.php
Mark Topper 924920e6e8
Feature/nodejs (#397)
* Add node support using nvm

* Add icon

* Rename to NodeJS

* Rename to NodeJS

* update php and node logo

* only services which have units can be started,restarted,stopped,disabled and enabled

* add tests

---------

Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
2024-12-24 17:49:27 +01:00

95 lines
2.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Enums\NodeJS;
use App\Enums\ServiceStatus;
use App\Facades\SSH;
use App\Models\Service;
use App\Web\Pages\Servers\NodeJS\Index;
use App\Web\Pages\Servers\NodeJS\Widgets\NodeJSList;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class NodeJSTest extends TestCase
{
use RefreshDatabase;
public function test_install_new_nodejs(): void
{
SSH::fake();
$this->actingAs($this->user);
Livewire::test(Index::class, ['server' => $this->server])
->callAction('install', [
'version' => NodeJS::V16,
])
->assertSuccessful();
$this->assertDatabaseHas('services', [
'server_id' => $this->server->id,
'type' => 'nodejs',
'version' => NodeJS::V16,
'status' => ServiceStatus::READY,
]);
}
public function test_uninstall_nodejs(): void
{
SSH::fake();
$this->actingAs($this->user);
$php = new Service([
'server_id' => $this->server->id,
'type' => 'nodejs',
'type_data' => [],
'name' => 'nodejs',
'version' => NodeJS::V16,
'status' => ServiceStatus::READY,
'is_default' => true,
]);
$php->save();
Livewire::test(NodeJSList::class, [
'server' => $this->server,
])
->callTableAction('uninstall', $php->id)
->assertSuccessful();
$this->assertDatabaseMissing('services', [
'id' => $php->id,
]);
}
public function test_change_default_nodejs_cli(): void
{
SSH::fake();
$this->actingAs($this->user);
/** @var Service $service */
$service = Service::factory()->create([
'server_id' => $this->server->id,
'type' => 'nodejs',
'type_data' => [],
'name' => 'nodejs',
'version' => NodeJS::V16,
'status' => ServiceStatus::READY,
'is_default' => false,
]);
Livewire::test(NodeJSList::class, [
'server' => $this->server,
])
->callTableAction('default-nodejs-cli', $service->id)
->assertSuccessful();
$service->refresh();
$this->assertTrue($service->is_default);
}
}