Path: blob/1.0-develop/tests/Integration/Services/Users/UserDeletionServiceTest.php
14044 views
<?php12namespace Pterodactyl\Tests\Integration\Services\Users;34use Pterodactyl\Models\User;5use Pterodactyl\Models\Subuser;6use Illuminate\Support\Facades\Bus;7use Pterodactyl\Jobs\RevokeSftpAccessJob;8use Pterodactyl\Exceptions\DisplayException;9use Pterodactyl\Services\Users\UserDeletionService;10use Pterodactyl\Tests\Integration\IntegrationTestCase;1112class UserDeletionServiceTest extends IntegrationTestCase13{14public function setUp(): void15{16parent::setUp();1718Bus::fake([RevokeSftpAccessJob::class]);19}2021public function testExceptionReturnedIfUserAssignedToServers(): void22{23$server = $this->createServerModel();2425$this->expectException(DisplayException::class);26$this->expectExceptionMessage(__('admin/user.exceptions.user_has_servers'));2728$this->app->make(UserDeletionService::class)->handle($server->user);2930$this->assertModelExists($server->user);3132Bus::assertNotDispatched(RevokeSftpAccessJob::class);33}3435public function testUserIsDeleted(): void36{37$user = User::factory()->create();3839$this->app->make(UserDeletionService::class)->handle($user);4041$this->assertModelMissing($user);4243Bus::assertNotDispatched(RevokeSftpAccessJob::class);44}4546public function testUserIsDeletedAndAccessRevoked(): void47{48$user = User::factory()->create();4950$server1 = $this->createServerModel();51$server2 = $this->createServerModel(['node_id' => $server1->node_id]);5253Subuser::factory()->for($server1)->for($user)->create();54Subuser::factory()->for($server2)->for($user)->create();5556$this->app->make(UserDeletionService::class)->handle($user);5758$this->assertModelMissing($user);5960Bus::assertDispatchedTimes(RevokeSftpAccessJob::class);61Bus::assertDispatched(fn (RevokeSftpAccessJob $job) => $job->user === $user->uuid && $job->target->is($server1->node));62}63}646566