2021-07-11 12:15:39 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Pest\Integration\Api\Client\Server\Backup\DeleteBackupTest;
|
2021-07-11 12:15:39 -07:00
|
|
|
|
|
|
|
|
use Illuminate\Http\Response;
|
2022-05-29 17:07:54 -04:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Enum\Permissions;
|
2022-05-29 17:07:54 -04:00
|
|
|
use Pterodactyl\Events\ActivityLogged;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\Backup;
|
2021-07-11 12:15:39 -07:00
|
|
|
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Tests\Support\Fakes\FakeDaemonBackup;
|
|
|
|
|
|
|
|
|
|
uses(ClientApiIntegrationTestCase::class);
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->repository = new FakeDaemonBackup;
|
|
|
|
|
});
|
|
|
|
|
test('user without permission cannot delete backup', function () {
|
|
|
|
|
[$user, $server] = $this->generateTestAccount([Permissions::BackupCreate->value]);
|
|
|
|
|
$backup = Backup::factory()->create(['server_id' => $server->id]);
|
|
|
|
|
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_FORBIDDEN);
|
|
|
|
|
});
|
|
|
|
|
test('backup can be deleted', function () {
|
|
|
|
|
Event::fake([ActivityLogged::class]);
|
|
|
|
|
[$user, $server] = $this->generateTestAccount([Permissions::BackupDelete->value]);
|
|
|
|
|
/** @var Backup $backup */
|
|
|
|
|
$backup = Backup::factory()->create(['server_id' => $server->id]);
|
|
|
|
|
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NO_CONTENT);
|
|
|
|
|
$backup->refresh();
|
|
|
|
|
$this->assertSoftDeleted($backup);
|
|
|
|
|
$this->repository->assertDeleted($backup->uuid);
|
|
|
|
|
$this->assertActivityFor('server:backup.delete', $user, [$backup, $backup->server]);
|
|
|
|
|
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NOT_FOUND);
|
|
|
|
|
});
|