fix(backup): implement drag-and-drop restore, direct auto-download, and backup history log

This commit is contained in:
Ray1111-aa
2026-10-28 11:14:47 +07:00
parent 7058cc57c6
commit 0d78318dfe
7 changed files with 699 additions and 103 deletions
+41
View File
@@ -269,4 +269,45 @@ class BackupAndRestoreTest extends TestCase
$this->assertStringContainsString('[email protected]', $sqlContent);
$this->assertStringNotContainsString('[email protected]', $sqlContent);
}
public function test_backup_creation_records_to_backup_logs_and_sets_auto_download(): void
{
$response = $this->actingAs($this->superAdmin)
->post(route('admin.backups.store'), [
'backup_scope' => 'pilihan',
'selected_tables' => ['users'],
]);
$response->assertSessionHas('success');
$response->assertSessionHas('auto_download');
$this->assertDatabaseHas('backup_logs', [
'user_id' => $this->superAdmin->id,
'scope' => 'pilihan',
]);
}
public function test_super_admin_can_restore_directly_from_uploaded_kmh_file(): void
{
$filename = $this->backupService->createKmhBackup(['users'], false, 'test_direct_restore.kmh');
$fullPath = $this->backupService->getBackupDirectory() . DIRECTORY_SEPARATOR . $filename;
$kmhContent = file_get_contents($fullPath);
$uploadedFile = UploadedFile::fake()->createWithContent('backup_dari_pc.kmh', $kmhContent);
$response = $this->actingAs($this->superAdmin)
->post(route('admin.backups.restore_file'), [
'backup_file' => $uploadedFile,
'confirmation' => 'PULIHKAN',
]);
$response->assertSessionHas('success');
$response->assertSessionMissing('error');
$this->assertDatabaseHas('admin_activity_logs', [
'action_type' => 'update',
'module' => 'Backup & Restore',
'target_name' => 'backup_dari_pc.kmh',
]);
}
}