mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-01 00:36:57 +01:00 
			
		
		
		
	 3d764a89f7
			
		
	
	
		3d764a89f7
		
			
		
	
	
	
	
		
			
			* chore: yarn upgrade * chore: composer upgrade * chore: php artisan filament:upgrade * chore: update filament-monaco-editor-views * chore: update filament-monaco-editor-configs * chore: move turnstile-views to plugins * fix monaco-editor loader & css
		
			
				
	
	
		
			65 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Tests\Integration\Api\Client\Server\Backup;
 | |
| 
 | |
| use Mockery\MockInterface;
 | |
| use Illuminate\Http\Response;
 | |
| use App\Models\Backup;
 | |
| use App\Models\Permission;
 | |
| use Illuminate\Support\Facades\Event;
 | |
| use App\Events\ActivityLogged;
 | |
| use App\Repositories\Daemon\DaemonBackupRepository;
 | |
| use App\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
 | |
| 
 | |
| class DeleteBackupTest extends ClientApiIntegrationTestCase
 | |
| {
 | |
|     private MockInterface $repository;
 | |
| 
 | |
|     protected function setUp(): void
 | |
|     {
 | |
|         parent::setUp();
 | |
| 
 | |
|         $this->repository = $this->mock(DaemonBackupRepository::class);
 | |
|     }
 | |
| 
 | |
|     public function test_user_without_permission_cannot_delete_backup(): void
 | |
|     {
 | |
|         [$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_CREATE]);
 | |
| 
 | |
|         $backup = Backup::factory()->create(['server_id' => $server->id]);
 | |
| 
 | |
|         $this->actingAs($user)->deleteJson($this->link($backup))
 | |
|             ->assertStatus(Response::HTTP_FORBIDDEN);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 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
 | |
|      * activity logs table for this API call.
 | |
|      */
 | |
|     public function test_backup_can_be_deleted(): void
 | |
|     {
 | |
|         Event::fake([ActivityLogged::class]);
 | |
| 
 | |
|         [$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_DELETE]);
 | |
| 
 | |
|         /** @var \App\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->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NO_CONTENT);
 | |
| 
 | |
|         $backup->refresh();
 | |
|         $this->assertSoftDeleted($backup);
 | |
| 
 | |
|         $this->assertActivityFor('server:backup.delete', $user, [$backup, $backup->server]);
 | |
| 
 | |
|         $this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NOT_FOUND);
 | |
|     }
 | |
| }
 |