This commit is contained in:
Laucha1312
2026-06-04 15:22:45 -03:00
parent cc70b74e5a
commit aa9bc585fd
12 changed files with 782 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use App\Models\Evento;
use App\Models\QrCode;
use Illuminate\Support\Facades\Artisan;
class CleanupTest extends TestCase
{
use DatabaseTransactions;
public function test_cleanup_only_removes_qrs_but_keeps_event()
{
// 1. Create an old event
$idEvento = 'old_evt_1';
Evento::create([
'id_evento' => $idEvento,
'nombre_evento' => 'Old Event',
'fecha_evento' => now()->subDays(40)->format('Y-m-d'),
'hora_inicio' => '10:00',
'hora_fin' => '12:00'
]);
// 2. Create a QR for this event
QrCode::create([
'id_qr' => 'qr_old_1',
'id_evento' => $idEvento,
'tipo_qr' => 'publico'
]);
// 3. Ensure they exist
$this->assertDatabaseHas('eventos', ['id_evento' => $idEvento]);
$this->assertDatabaseHas('qr_codes', ['id_qr' => 'qr_old_1']);
// 4. Run the cleanup command
Artisan::call('app:cleanup-old-events');
// 5. Verify QRs are gone but event remains
$this->assertDatabaseMissing('qr_codes', ['id_qr' => 'qr_old_1']);
$this->assertDatabaseHas('eventos', ['id_evento' => $idEvento]);
}
}