2026-07-15 13:47:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
|
use App\Models\Environment;
|
|
|
|
|
use App\Models\InstanceSettings;
|
|
|
|
|
use App\Models\LocalPersistentVolume;
|
|
|
|
|
use App\Models\Project;
|
2026-07-16 12:30:58 +00:00
|
|
|
use App\Models\S3Storage;
|
2026-07-15 13:47:57 +00:00
|
|
|
use App\Models\Server;
|
|
|
|
|
use App\Models\StandaloneDocker;
|
|
|
|
|
use App\Models\StandalonePostgresql;
|
|
|
|
|
use App\Models\Team;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2026-07-15 15:34:22 +00:00
|
|
|
config(['app.maintenance.driver' => 'file']);
|
2026-07-15 13:47:57 +00:00
|
|
|
InstanceSettings::forceCreate(['id' => 0]);
|
|
|
|
|
|
|
|
|
|
$this->team = Team::factory()->create();
|
|
|
|
|
$this->user = User::factory()->create();
|
|
|
|
|
$this->user->teams()->attach($this->team, ['role' => 'owner']);
|
|
|
|
|
$this->actingAs($this->user);
|
|
|
|
|
session(['currentTeam' => $this->team]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders frontend-only application backup search data for volume names and frequencies', function () {
|
|
|
|
|
$application = createBackupSearchApplication($this->team);
|
|
|
|
|
$dailyVolume = createBackupSearchVolume($application, 'app-data');
|
|
|
|
|
$weeklyVolume = createBackupSearchVolume($application, 'Cache-Data');
|
|
|
|
|
|
2026-07-15 15:34:22 +00:00
|
|
|
$dailyVolume->scheduledBackups()->create([
|
2026-07-15 13:47:57 +00:00
|
|
|
'team_id' => $this->team->id,
|
|
|
|
|
'frequency' => 'daily',
|
|
|
|
|
]);
|
2026-07-15 15:34:22 +00:00
|
|
|
$weeklyVolume->scheduledBackups()->create([
|
2026-07-15 13:47:57 +00:00
|
|
|
'team_id' => $this->team->id,
|
|
|
|
|
'frequency' => '0 4 * * 0',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$parameters = [
|
|
|
|
|
'project_uuid' => $application->project()->uuid,
|
|
|
|
|
'environment_uuid' => $application->environment->uuid,
|
|
|
|
|
'application_uuid' => $application->uuid,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->get(route('project.application.backup.index', [...$parameters, 'search' => 'cache']))
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertSee('Cache-Data')
|
|
|
|
|
->assertSee('Volume: app-data')
|
2026-07-15 15:34:22 +00:00
|
|
|
->assertSee("search: 'cache'", false)
|
2026-07-15 13:47:57 +00:00
|
|
|
->assertSee('x-model="search"', false)
|
|
|
|
|
->assertSee('x-show=', false)
|
|
|
|
|
->assertSee('No scheduled backups match your search.');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders frontend-only database backup search data for database names and frequencies', function () {
|
|
|
|
|
$server = Server::factory()->create(['team_id' => $this->team->id]);
|
|
|
|
|
$destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();
|
|
|
|
|
$project = Project::factory()->create(['team_id' => $this->team->id]);
|
|
|
|
|
$environment = Environment::factory()->create(['project_id' => $project->id]);
|
|
|
|
|
$database = StandalonePostgresql::create([
|
|
|
|
|
'name' => 'Orders-Primary',
|
|
|
|
|
'image' => 'postgres:16-alpine',
|
|
|
|
|
'postgres_user' => 'postgres',
|
|
|
|
|
'postgres_password' => 'password',
|
|
|
|
|
'postgres_db' => 'postgres',
|
|
|
|
|
'environment_id' => $environment->id,
|
|
|
|
|
'destination_id' => $destination->id,
|
|
|
|
|
'destination_type' => $destination->getMorphClass(),
|
|
|
|
|
]);
|
2026-07-16 12:30:58 +00:00
|
|
|
$storage = S3Storage::create([
|
|
|
|
|
'name' => 'Archive-Bucket',
|
|
|
|
|
'region' => 'us-east-1',
|
|
|
|
|
'key' => 'test-key',
|
|
|
|
|
'secret' => 'test-secret',
|
|
|
|
|
'bucket' => 'test-bucket',
|
|
|
|
|
'endpoint' => 'https://s3.example.com',
|
|
|
|
|
'is_usable' => true,
|
|
|
|
|
'team_id' => $this->team->id,
|
|
|
|
|
]);
|
2026-07-15 13:47:57 +00:00
|
|
|
$database->scheduledBackups()->create([
|
|
|
|
|
'team_id' => $this->team->id,
|
|
|
|
|
'frequency' => 'daily',
|
2026-07-16 12:30:58 +00:00
|
|
|
'save_s3' => true,
|
|
|
|
|
's3_storage_id' => $storage->id,
|
2026-07-15 13:47:57 +00:00
|
|
|
]);
|
|
|
|
|
$database->scheduledBackups()->create([
|
|
|
|
|
'team_id' => $this->team->id,
|
|
|
|
|
'frequency' => '0 3 * * 1',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$parameters = [
|
|
|
|
|
'project_uuid' => $project->uuid,
|
|
|
|
|
'environment_uuid' => $environment->uuid,
|
|
|
|
|
'database_uuid' => $database->uuid,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->get(route('project.database.backup.index', [...$parameters, 'search' => '0 3']))
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertSee('<h3 class="font-semibold">0 3 * * 1</h3>', false)
|
|
|
|
|
->assertSee('<h3 class="font-semibold">daily</h3>', false)
|
2026-07-16 12:30:58 +00:00
|
|
|
->assertSee('S3: Archive-Bucket')
|
|
|
|
|
->assertSee('archive-bucket', false)
|
|
|
|
|
->assertSee('backup.s3_storage.includes(query)', false)
|
|
|
|
|
->assertSee('Search by database name, frequency, or S3 storage...')
|
2026-07-15 13:47:57 +00:00
|
|
|
->assertSee('x-model="search"', false)
|
|
|
|
|
->assertSee('x-show=', false)
|
|
|
|
|
->assertSee('No scheduled backups match your search.');
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-16 12:30:58 +00:00
|
|
|
it('renders unavailable S3 storage only for S3-enabled database backups', function () {
|
|
|
|
|
$server = Server::factory()->create(['team_id' => $this->team->id]);
|
|
|
|
|
$destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();
|
|
|
|
|
$project = Project::factory()->create(['team_id' => $this->team->id]);
|
|
|
|
|
$environment = Environment::factory()->create(['project_id' => $project->id]);
|
|
|
|
|
$database = StandalonePostgresql::create([
|
|
|
|
|
'name' => 'Orders-Primary',
|
|
|
|
|
'image' => 'postgres:16-alpine',
|
|
|
|
|
'postgres_user' => 'postgres',
|
|
|
|
|
'postgres_password' => 'password',
|
|
|
|
|
'postgres_db' => 'postgres',
|
|
|
|
|
'environment_id' => $environment->id,
|
|
|
|
|
'destination_id' => $destination->id,
|
|
|
|
|
'destination_type' => $destination->getMorphClass(),
|
|
|
|
|
]);
|
|
|
|
|
$database->scheduledBackups()->create([
|
|
|
|
|
'team_id' => $this->team->id,
|
|
|
|
|
'frequency' => 'daily',
|
|
|
|
|
'save_s3' => true,
|
|
|
|
|
's3_storage_id' => null,
|
|
|
|
|
]);
|
|
|
|
|
$database->scheduledBackups()->create([
|
|
|
|
|
'team_id' => $this->team->id,
|
|
|
|
|
'frequency' => 'weekly',
|
|
|
|
|
'save_s3' => false,
|
|
|
|
|
's3_storage_id' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$parameters = [
|
|
|
|
|
'project_uuid' => $project->uuid,
|
|
|
|
|
'environment_uuid' => $environment->uuid,
|
|
|
|
|
'database_uuid' => $database->uuid,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->get(route('project.database.backup.index', $parameters))
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertSee('S3: Storage unavailable');
|
|
|
|
|
|
|
|
|
|
expect(substr_count($response->getContent(), 'S3:'))->toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-15 13:47:57 +00:00
|
|
|
function createBackupSearchApplication(Team $team): Application
|
|
|
|
|
{
|
|
|
|
|
$server = Server::factory()->create(['team_id' => $team->id]);
|
|
|
|
|
$destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();
|
|
|
|
|
$project = Project::factory()->create(['team_id' => $team->id]);
|
|
|
|
|
$environment = Environment::factory()->create(['project_id' => $project->id]);
|
|
|
|
|
$application = Application::factory()->create([
|
|
|
|
|
'environment_id' => $environment->id,
|
|
|
|
|
'destination_id' => $destination->id,
|
|
|
|
|
'destination_type' => $destination->getMorphClass(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return $application;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createBackupSearchVolume(Application $application, string $name): LocalPersistentVolume
|
|
|
|
|
{
|
|
|
|
|
return LocalPersistentVolume::create([
|
|
|
|
|
'name' => $name,
|
|
|
|
|
'mount_path' => '/'.str($name)->lower(),
|
|
|
|
|
'resource_id' => $application->id,
|
|
|
|
|
'resource_type' => $application->getMorphClass(),
|
|
|
|
|
]);
|
|
|
|
|
}
|