109 lines
4.0 KiB
PHP
109 lines
4.0 KiB
PHP
<?php
|
|
|
|
use App\Filament\Pages\UnitaImmobiliarePage;
|
|
use App\Models\Stabile;
|
|
use App\Models\UnitaImmobiliare;
|
|
use App\Models\User;
|
|
use App\Support\AnnoGestioneContext;
|
|
use App\Support\StabileContext;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
beforeEach(function () {
|
|
DB::table('amministratori')->insertOrIgnore(['id' => 1, 'nome' => 'Admin Test', 'cognome' => 'Test', 'created_at' => now(), 'updated_at' => now()]);
|
|
|
|
$stabile = Stabile::where('codice_stabile', '0021')->first();
|
|
if (! $stabile) {
|
|
$mirrorCount = DB::connection('gescon_import')
|
|
->table('condomin_mirror')
|
|
->where('cod_stabile', '0021')
|
|
->count();
|
|
if ($mirrorCount === 0) {
|
|
Artisan::call('gescon:import-mirror-0021');
|
|
}
|
|
Artisan::call('gescon:reconstruct-mirror-0021');
|
|
$stabile = Stabile::where('codice_stabile', '0021')->first();
|
|
}
|
|
});
|
|
|
|
test('gescon:bonifica-duplicati-benedetto command is 100% idempotent across two runs', function () {
|
|
// 1st Run
|
|
$exitCode1 = Artisan::call('gescon:bonifica-duplicati-benedetto');
|
|
expect($exitCode1)->toBe(0);
|
|
|
|
// 2nd Run
|
|
$exitCode2 = Artisan::call('gescon:bonifica-duplicati-benedetto');
|
|
expect($exitCode2)->toBe(0);
|
|
|
|
$duplicatePurCount = DB::table('persone_unita_relazioni')->whereIn('persona_id', [277, 278])->count();
|
|
$duplicateRrCount = DB::table('rubrica_ruoli')->whereIn('rubrica_id', [651, 652, 973, 974])->count();
|
|
|
|
expect($duplicatePurCount)->toBe(0);
|
|
expect($duplicateRrCount)->toBe(0);
|
|
});
|
|
|
|
test('authenticated UI mounts A/11, CAN/11, and A/10 without duplicate cards', function () {
|
|
Artisan::call('gescon:bonifica-duplicati-benedetto');
|
|
|
|
$user = User::first();
|
|
if (! $user) {
|
|
$user = User::factory()->create();
|
|
}
|
|
expect($user)->not->toBeNull();
|
|
|
|
try {
|
|
if (method_exists($user, 'assignRole')) {
|
|
\Spatie\Permission\Models\Role::firstOrCreate(['name' => 'admin', 'guard_name' => 'web']);
|
|
$user->assignRole('admin');
|
|
}
|
|
} catch (\Throwable $e) {}
|
|
|
|
$stabile = Stabile::where('codice_stabile', '0021')->first();
|
|
expect($stabile)->not->toBeNull();
|
|
|
|
$unitA11 = UnitaImmobiliare::where('stabile_id', $stabile->id)->where('scala', 'A')->where('interno', '11')->first();
|
|
expect($unitA11)->not->toBeNull();
|
|
|
|
Auth::login($user);
|
|
StabileContext::setActiveStabileId($user, $stabile->id);
|
|
|
|
// 1. Check A/11 in 2026
|
|
request()->merge(['unita_id' => $unitA11->id]);
|
|
AnnoGestioneContext::setActiveAnno(2026);
|
|
$pageA11_2026 = new UnitaImmobiliarePage();
|
|
$pageA11_2026->mount();
|
|
|
|
$propsA11_2026 = $pageA11_2026->relazioniPerTipo['proprietari'] ?? [];
|
|
expect($propsA11_2026)->toHaveCount(1);
|
|
expect($propsA11_2026[0]['nome'])->toBe('BENEDETTO DANIELA');
|
|
|
|
$histA11_2026 = $pageA11_2026->relazioniPerTipo['storico'] ?? [];
|
|
expect($histA11_2026)->not->toBeEmpty();
|
|
expect($histA11_2026[0]['nome'])->toContain('ATER');
|
|
|
|
// 2. Check CAN/11 (if present in test DB)
|
|
$unitCAN11 = UnitaImmobiliare::where('stabile_id', $stabile->id)->where('interno', 'LIKE', '%11%')->where('interno', '!=', '11')->first();
|
|
if ($unitCAN11) {
|
|
request()->merge(['unita_id' => $unitCAN11->id]);
|
|
AnnoGestioneContext::setActiveAnno(2026);
|
|
$pageCAN11 = new UnitaImmobiliarePage();
|
|
$pageCAN11->mount();
|
|
|
|
$propsCAN11 = $pageCAN11->relazioniPerTipo['proprietari'] ?? [];
|
|
expect($propsCAN11)->not->toBeNull();
|
|
}
|
|
|
|
// 3. Check A/10 in 2026
|
|
$unitA10 = UnitaImmobiliare::where('stabile_id', $stabile->id)->where('scala', 'A')->where('interno', '10')->first();
|
|
if ($unitA10) {
|
|
request()->merge(['unita_id' => $unitA10->id]);
|
|
AnnoGestioneContext::setActiveAnno(2026);
|
|
$pageA10_2026 = new UnitaImmobiliarePage();
|
|
$pageA10_2026->mount();
|
|
|
|
$altriA10_2026 = $pageA10_2026->relazioniPerTipo['altri'] ?? [];
|
|
expect($altriA10_2026)->toBeEmpty();
|
|
}
|
|
});
|