Files

34 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Tests\Pest\Integration\Console\Commands\Location\LocationCommandsTest;
2026-10-11 14:33:37 -04:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Location;
use Pterodactyl\Models\Node;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
2026-10-11 14:33:37 -04:00
uses(IntegrationTestCase::class, DatabaseTransactions::class);
2026-10-05 18:10:18 -04:00
test('make creates a location', function () {
$this->artisan('p:location:make', ['--short' => 'cli-made', '--long' => 'Made from the CLI'])->assertExitCode(0);
$this->assertDatabaseHas('locations', ['short' => 'cli-made', 'long' => 'Made from the CLI']);
});
test('make rejects a duplicate short code', function () {
Location::factory()->create(['short' => 'cli-dupe']);
$this->artisan('p:location:make', ['--short' => 'cli-dupe', '--long' => 'Duplicate'])->assertExitCode(1);
expect(Location::query()->where('short', 'cli-dupe')->count())->toBe(1);
});
test('delete removes an empty location', function () {
$location = Location::factory()->create(['short' => 'cli-gone']);
$this->artisan('p:location:delete', ['--short' => 'cli-gone'])->assertExitCode(0);
$this->assertDatabaseMissing('locations', ['id' => $location->id]);
});
test('delete refuses a location with nodes', function () {
$location = Location::factory()->create(['short' => 'cli-busy']);
Node::factory()->create(['location_id' => $location->id]);
expect(fn () => $this->artisan('p:location:delete', ['--short' => 'cli-busy']))
->toThrow(\Pterodactyl\Exceptions\Service\Location\HasActiveNodesException::class);
$this->assertDatabaseHas('locations', ['id' => $location->id]);
});