This commit is contained in:
Saeed Vaziry
2024-03-24 09:56:34 +01:00
committed by GitHub
parent 884f18db63
commit 4d051330d6
1055 changed files with 14493 additions and 20278 deletions

View File

@ -4,14 +4,9 @@
use App\Enums\SslStatus;
use App\Enums\SslType;
use App\Http\Livewire\Ssl\CreateSsl;
use App\Http\Livewire\Ssl\SslsList;
use App\Jobs\Ssl\Deploy;
use App\Jobs\Ssl\Remove;
use App\Facades\SSH;
use App\Models\Ssl;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
use Tests\TestCase;
class SslTest extends TestCase
@ -26,41 +21,72 @@ public function test_see_ssls_list()
'site_id' => $this->site->id,
]);
Livewire::test(SslsList::class, ['site' => $this->site])
->assertSeeText($ssl->type);
$this->get(route('servers.sites.ssl', [
'server' => $this->server,
'site' => $this->site,
]))
->assertOk()
->assertSee($ssl->type);
}
public function test_see_ssls_list_with_no_ssls()
{
$this->actingAs($this->user);
Livewire::test(SslsList::class, ['site' => $this->site])
$this->get(route('servers.sites.ssl', [
'server' => $this->server,
'site' => $this->site,
]))
->assertOk()
->assertSeeText(__("You don't have any SSL certificates yet!"));
}
public function test_create_ssl()
public function test_letsencrypt_ssl()
{
Bus::fake();
SSH::fake('Successfully received certificate');
$this->actingAs($this->user);
Livewire::test(CreateSsl::class, ['site' => $this->site])
->set('type', SslType::LETSENCRYPT)
->call('create')
->assertDispatched('created');
$this->post(route('servers.sites.ssl.store', [
'server' => $this->server,
'site' => $this->site,
]), [
'type' => SslType::LETSENCRYPT,
])->assertSessionDoesntHaveErrors();
$this->assertDatabaseHas('ssls', [
'site_id' => $this->site->id,
'type' => SslType::LETSENCRYPT,
'status' => SslStatus::CREATING,
'status' => SslStatus::CREATED,
]);
}
Bus::assertDispatched(Deploy::class);
public function test_custom_ssl()
{
SSH::fake('Successfully received certificate');
$this->actingAs($this->user);
$this->post(route('servers.sites.ssl.store', [
'server' => $this->server,
'site' => $this->site,
]), [
'type' => SslType::CUSTOM,
'certificate' => 'certificate',
'private' => 'private',
'expires_at' => now()->addYear()->format('Y-m-d'),
])->assertSessionDoesntHaveErrors();
$this->assertDatabaseHas('ssls', [
'site_id' => $this->site->id,
'type' => SslType::CUSTOM,
'status' => SslStatus::CREATED,
]);
}
public function test_delete_ssl()
{
Bus::fake();
SSH::fake();
$this->actingAs($this->user);
@ -68,16 +94,14 @@ public function test_delete_ssl()
'site_id' => $this->site->id,
]);
Livewire::test(SslsList::class, ['site' => $this->site])
->set('deleteId', $ssl->id)
->call('delete')
->assertDispatched('confirmed');
$this->delete(route('servers.sites.ssl.destroy', [
'server' => $this->server,
'site' => $this->site,
'ssl' => $ssl,
]))->assertRedirect();
$this->assertDatabaseHas('ssls', [
$this->assertDatabaseMissing('ssls', [
'id' => $ssl->id,
'status' => SslStatus::DELETING,
]);
Bus::assertDispatched(Remove::class);
}
}