Added user and organization deletion system; Added coverage annotations

This commit is contained in:
Constantin Graf
2024-06-07 19:17:40 +02:00
committed by Constantin Graf
parent 8857befc6c
commit 86f5ea47bb
65 changed files with 2651 additions and 135 deletions

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Console\Commands\Admin;
use App\Models\Organization;
use App\Service\DeletionService;
use Illuminate\Support\Str;
use Mockery\MockInterface;
use Tests\TestCaseWithDatabase;
class DeleteOrganizationCommandTest extends TestCaseWithDatabase
{
public function test_it_calls_the_deletion_service_with_the_organization(): void
{
// Arrange
$organization = Organization::factory()->create();
$this->mock(DeletionService::class, function (MockInterface $mock) use ($organization): void {
$mock->shouldReceive('deleteOrganization')
->withArgs(fn (Organization $organizationArg) => $organizationArg->is($organization))
->once();
});
// Act
$this->artisan('admin:delete-organization', ['organization' => $organization->getKey()])
->expectsOutput("Deleting organization with ID {$organization->getKey()}")
->expectsOutput("Organization with ID {$organization->getKey()} has been deleted.")
->assertExitCode(0);
}
public function test_it_fails_if_organization_does_not_exist(): void
{
// Arrange
$organizationId = Str::uuid()->toString();
// Act
$this->artisan('admin:delete-organization', ['organization' => $organizationId])
->expectsOutput('Organization with ID '.$organizationId.' not found.')
->assertExitCode(1);
}
public function test_it_fails_if_organization_id_is_not_a_valid_uuid(): void
{
// Arrange
$organizationId = 'invalid-uuid';
// Act
$this->artisan('admin:delete-organization', ['organization' => $organizationId])
->expectsOutput('Organization ID must be a valid UUID.')
->assertExitCode(1);
}
}

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Console\Commands\SelfHost;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class SelfHostGenerateKeysCommandTest extends TestCase
{
public function test_generates_app_key_and_passport_keys_per_default_in_env_format(): void
{
// Arrange
// Act
$exitCode = $this->withoutMockingConsoleOutput()->artisan('self-host:generate-keys');
// Assert
$this->assertSame(Command::SUCCESS, $exitCode);
$output = Artisan::output();
$this->assertStringContainsString('APP_KEY="base64:', $output);
$this->assertStringContainsString('PASSPORT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----', $output);
$this->assertStringContainsString('PASSPORT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----', $output);
}
public function test_generates_app_key_and_passport_keys_in_yaml_format_if_requested(): void
{
// Arrange
// Act
$exitCode = $this->withoutMockingConsoleOutput()->artisan('self-host:generate-keys --format=yaml');
// Assert
$this->assertSame(Command::SUCCESS, $exitCode);
$output = Artisan::output();
$this->assertStringContainsString('APP_KEY: "base64:', $output);
$this->assertStringContainsString("PASSPORT_PRIVATE_KEY: |\n -----BEGIN PRIVATE KEY-----", $output);
$this->assertStringContainsString("PASSPORT_PUBLIC_KEY: |\n -----BEGIN PUBLIC KEY-----", $output);
}
}