Ensure we can properly create an activity log entry; always return soft-deleted models
This commit is contained in:
parent
f1c1699994
commit
09832cc558
5 changed files with 106 additions and 29 deletions
|
@ -5,8 +5,9 @@ namespace Pterodactyl\Tests\Integration\Api\Client\Server\Backup;
|
|||
use Mockery;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\AuditLog;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Pterodactyl\Events\ActivityLogged;
|
||||
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
|
||||
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
||||
|
||||
|
@ -34,32 +35,41 @@ class DeleteBackupTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Tests that a backup can be deleted for a server and that it is properly updated
|
||||
* in the database. Once deleted there should also be a corresponding record in the
|
||||
* audit logs table for this API call.
|
||||
* activity logs table for this API call.
|
||||
*/
|
||||
public function testBackupCanBeDeleted()
|
||||
{
|
||||
Event::fake([ActivityLogged::class]);
|
||||
|
||||
[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_DELETE]);
|
||||
|
||||
/** @var \Pterodactyl\Models\Backup $backup */
|
||||
$backup = Backup::factory()->create(['server_id' => $server->id]);
|
||||
|
||||
$this->repository->expects('setServer->delete')->with(Mockery::on(function ($value) use ($backup) {
|
||||
return $value instanceof Backup && $value->uuid === $backup->uuid;
|
||||
}))->andReturn(new Response());
|
||||
$this->repository->expects('setServer->delete')->with(
|
||||
Mockery::on(function ($value) use ($backup) {
|
||||
return $value instanceof Backup && $value->uuid === $backup->uuid;
|
||||
})
|
||||
)->andReturn(new Response());
|
||||
|
||||
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NO_CONTENT);
|
||||
|
||||
$backup->refresh();
|
||||
$this->assertSoftDeleted($backup);
|
||||
|
||||
$this->assertNotNull($backup->deleted_at);
|
||||
Event::assertDispatched(ActivityLogged::class, function (ActivityLogged $event) use ($backup, $user) {
|
||||
$this->assertTrue($event->isServerEvent());
|
||||
$this->assertTrue($event->is('server:backup.delete'));
|
||||
$this->assertTrue($user->is($event->actor()));
|
||||
$this->assertCount(2, $event->model->subjects);
|
||||
|
||||
$subjects = $event->model->subjects;
|
||||
$this->assertCount(1, $subjects->filter(fn ($model) => $model->subject->is($backup)));
|
||||
$this->assertCount(1, $subjects->filter(fn ($model) => $model->subject->is($backup->server)));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NOT_FOUND);
|
||||
|
||||
$event = $backup->audits()->where('action', AuditLog::SERVER__BACKUP_DELETED)->latest()->first();
|
||||
|
||||
$this->assertNotNull($event);
|
||||
$this->assertFalse($event->is_system);
|
||||
$this->assertEquals($backup->server_id, $event->server_id);
|
||||
$this->assertEquals($user->id, $event->user_id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue