mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
tests
This commit is contained in:
@ -6,7 +6,12 @@
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Script;
|
||||
use App\Models\ScriptExecution;
|
||||
use App\Web\Pages\Scripts\Executions;
|
||||
use App\Web\Pages\Scripts\Index;
|
||||
use App\Web\Pages\Scripts\Widgets\ScriptExecutionsList;
|
||||
use App\Web\Pages\Scripts\Widgets\ScriptsList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ScriptTest extends TestCase
|
||||
@ -21,9 +26,7 @@ public function test_see_scripts(): void
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$this->get(
|
||||
route('scripts.index')
|
||||
)
|
||||
$this->get(Index::getUrl())
|
||||
->assertSuccessful()
|
||||
->assertSee($script->name);
|
||||
}
|
||||
@ -32,15 +35,12 @@ public function test_create_script(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(
|
||||
route('scripts.store'),
|
||||
[
|
||||
Livewire::test(Index::class)
|
||||
->callAction('create', [
|
||||
'name' => 'Test Script',
|
||||
'content' => 'echo "Hello, World!"',
|
||||
]
|
||||
)
|
||||
->assertSessionDoesntHaveErrors()
|
||||
->assertHeader('HX-Redirect');
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('scripts', [
|
||||
'name' => 'Test Script',
|
||||
@ -56,12 +56,12 @@ public function test_edit_script(): void
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$this->post(route('scripts.edit', ['script' => $script]), [
|
||||
'name' => 'New Name',
|
||||
'content' => 'echo "Hello, new World!"',
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertHeader('HX-Redirect');
|
||||
Livewire::test(ScriptsList::class)
|
||||
->callTableAction('edit', $script->id, [
|
||||
'name' => 'New Name',
|
||||
'content' => 'echo "Hello, new World!"',
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('scripts', [
|
||||
'id' => $script->id,
|
||||
@ -83,11 +83,9 @@ public function test_delete_script(): void
|
||||
'status' => ScriptExecutionStatus::EXECUTING,
|
||||
]);
|
||||
|
||||
$this->delete(
|
||||
route('scripts.delete', [
|
||||
'script' => $script,
|
||||
])
|
||||
)->assertRedirect();
|
||||
Livewire::test(ScriptsList::class)
|
||||
->callTableAction('delete', $script->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('scripts', [
|
||||
'id' => $script->id,
|
||||
@ -108,17 +106,14 @@ public function test_execute_script_and_view_log(): void
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$this->post(
|
||||
route('scripts.execute', [
|
||||
'script' => $script,
|
||||
]),
|
||||
[
|
||||
Livewire::test(Executions::class, [
|
||||
'script' => $script,
|
||||
])
|
||||
->callAction('execute', [
|
||||
'server' => $this->server->id,
|
||||
'user' => 'root',
|
||||
]
|
||||
)
|
||||
->assertSessionDoesntHaveErrors()
|
||||
->assertHeader('HX-Redirect');
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('script_executions', [
|
||||
'script_id' => $script->id,
|
||||
@ -131,14 +126,11 @@ public function test_execute_script_and_view_log(): void
|
||||
|
||||
$execution = $script->lastExecution;
|
||||
|
||||
$this->get(
|
||||
route('scripts.log', [
|
||||
'script' => $script,
|
||||
'execution' => $execution,
|
||||
])
|
||||
)
|
||||
->assertRedirect()
|
||||
->assertSessionHas('content', 'script output');
|
||||
Livewire::test(ScriptExecutionsList::class, [
|
||||
'script' => $script,
|
||||
])
|
||||
->callTableAction('logs', $execution->id)
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_see_executions(): void
|
||||
@ -154,11 +146,7 @@ public function test_see_executions(): void
|
||||
'status' => ScriptExecutionStatus::EXECUTING,
|
||||
]);
|
||||
|
||||
$this->get(
|
||||
route('scripts.show', [
|
||||
'script' => $script,
|
||||
])
|
||||
)
|
||||
$this->get(Executions::getUrl(['script' => $script]))
|
||||
->assertSuccessful()
|
||||
->assertSee($scriptExecution->status);
|
||||
}
|
||||
|
Reference in New Issue
Block a user