fix tests

This commit is contained in:
Boy132
2026-01-20 10:36:32 +01:00
parent efebb999df
commit 150f8035d6
5 changed files with 52 additions and 8 deletions

View File

@@ -24,7 +24,6 @@ class BackupFactory extends Factory
return [
'uuid' => Uuid::uuid4()->toString(),
'name' => $this->faker->sentence(),
'disk' => 'wings',
'is_successful' => true,
'created_at' => CarbonImmutable::now(),
'completed_at' => CarbonImmutable::now(),

View File

@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\BackupHost;
use Illuminate\Database\Eloquent\Factories\Factory;
class BackupHostFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = BackupHost::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'name' => $this->faker->colorName(),
'schema' => 'wings',
'configuration' => null,
];
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Tests\Integration\Api\Client\Server\Backup;
use App\Models\Backup;
use App\Models\BackupHost;
use App\Models\Subuser;
use App\Services\Backups\DeleteBackupService;
use App\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
@@ -25,9 +26,11 @@ class BackupAuthorizationTest extends ClientApiIntegrationTestCase
// to do anything with the backups for that server.
Subuser::factory()->create(['server_id' => $server2->id, 'user_id' => $user->id]);
$backup1 = Backup::factory()->create(['server_id' => $server1->id, 'completed_at' => CarbonImmutable::now()]);
$backup2 = Backup::factory()->create(['server_id' => $server2->id, 'completed_at' => CarbonImmutable::now()]);
$backup3 = Backup::factory()->create(['server_id' => $server3->id, 'completed_at' => CarbonImmutable::now()]);
$backupHost = BackupHost::factory()->create();
$backup1 = Backup::factory()->create(['server_id' => $server1->id, 'backup_host_id' => $backupHost->id, 'completed_at' => CarbonImmutable::now()]);
$backup2 = Backup::factory()->create(['server_id' => $server2->id, 'backup_host_id' => $backupHost->id, 'completed_at' => CarbonImmutable::now()]);
$backup3 = Backup::factory()->create(['server_id' => $server3->id, 'backup_host_id' => $backupHost->id, 'completed_at' => CarbonImmutable::now()]);
$this->instance(DeleteBackupService::class, $mock = \Mockery::mock(DeleteBackupService::class));

View File

@@ -5,6 +5,7 @@ namespace App\Tests\Integration\Api\Client\Server\Backup;
use App\Enums\SubuserPermission;
use App\Events\ActivityLogged;
use App\Models\Backup;
use App\Models\BackupHost;
use App\Repositories\Daemon\DaemonBackupRepository;
use App\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
use Illuminate\Http\Response;
@@ -26,7 +27,8 @@ class DeleteBackupTest extends ClientApiIntegrationTestCase
{
[$user, $server] = $this->generateTestAccount([SubuserPermission::BackupCreate]);
$backup = Backup::factory()->create(['server_id' => $server->id]);
$backupHost = BackupHost::factory()->create();
$backup = Backup::factory()->create(['server_id' => $server->id, 'backup_host_id' => $backupHost->id]);
$this->actingAs($user)->deleteJson($this->link($backup))
->assertStatus(Response::HTTP_FORBIDDEN);
@@ -43,8 +45,9 @@ class DeleteBackupTest extends ClientApiIntegrationTestCase
[$user, $server] = $this->generateTestAccount([SubuserPermission::BackupDelete]);
$backupHost = BackupHost::factory()->create();
/** @var \App\Models\Backup $backup */
$backup = Backup::factory()->create(['server_id' => $server->id]);
$backup = Backup::factory()->create(['server_id' => $server->id, 'backup_host_id' => $backupHost->id]);
$this->repository->expects('setServer->delete')->with(
\Mockery::on(function ($value) use ($backup) {

View File

@@ -4,6 +4,7 @@ namespace App\Tests\Integration\Services\Backups;
use App\Exceptions\Service\Backup\BackupLockedException;
use App\Models\Backup;
use App\Models\BackupHost;
use App\Repositories\Daemon\DaemonBackupRepository;
use App\Services\Backups\DeleteBackupService;
use App\Tests\Integration\IntegrationTestCase;
@@ -15,8 +16,11 @@ class DeleteBackupServiceTest extends IntegrationTestCase
public function test_locked_backup_cannot_be_deleted(): void
{
$server = $this->createServerModel();
$backupHost = BackupHost::factory()->create();
$backup = Backup::factory()->create([
'server_id' => $server->id,
'backup_host_id' => $backupHost->id,
'is_locked' => true,
]);
@@ -28,8 +32,11 @@ class DeleteBackupServiceTest extends IntegrationTestCase
public function test_failed_backup_that_is_locked_can_be_deleted(): void
{
$server = $this->createServerModel();
$backupHost = BackupHost::factory()->create();
$backup = Backup::factory()->create([
'server_id' => $server->id,
'backup_host_id' => $backupHost->id,
'is_locked' => true,
'is_successful' => false,
]);
@@ -47,7 +54,9 @@ class DeleteBackupServiceTest extends IntegrationTestCase
public function test_exception_thrown_due_to_missing_backup_is_ignored(): void
{
$server = $this->createServerModel();
$backup = Backup::factory()->create(['server_id' => $server->id]);
$backupHost = BackupHost::factory()->create();
$backup = Backup::factory()->create(['server_id' => $server->id, 'backup_host_id' => $backupHost->id]);
$mock = $this->mock(DaemonBackupRepository::class);
$mock->expects('setServer->delete')->with($backup)->andThrow(new ConnectionException(code: 404));
@@ -62,7 +71,9 @@ class DeleteBackupServiceTest extends IntegrationTestCase
public function test_exception_is_thrown_if_not404(): void
{
$server = $this->createServerModel();
$backup = Backup::factory()->create(['server_id' => $server->id]);
$backupHost = BackupHost::factory()->create();
$backup = Backup::factory()->create(['server_id' => $server->id, 'backup_host_id' => $backupHost->id]);
$mock = $this->mock(DaemonBackupRepository::class);
$mock->expects('setServer->delete')->with($backup)->andThrow(new ConnectionException(code: 500));