109 lines
4.0 KiB
PHP
109 lines
4.0 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Models\UnitaImmobiliare;
|
|
use App\Models\Stabile;
|
|
use App\Models\FeCassettoServiceConfig;
|
|
use App\Filament\Pages\Condomini\CatastoHub;
|
|
use App\Services\SisterCatastoService;
|
|
use App\Support\StabileContext;
|
|
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()]);
|
|
});
|
|
|
|
test('catasto hub mounts and loads Stabile 0013 with genuine DB data and no Milizie fallbacks', function () {
|
|
$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) {}
|
|
|
|
Auth::login($user);
|
|
|
|
$stabile0013 = Stabile::firstOrCreate(
|
|
['codice_stabile' => '0013'],
|
|
[
|
|
'amministratore_id' => 1,
|
|
'denominazione' => 'OTTAVIANO 105 - GIULIO CESARE 171',
|
|
'indirizzo' => 'VIA OTTAVIANO 105 - V.LE G. CESARE 171',
|
|
'cap' => '00192',
|
|
'citta' => 'ROMA',
|
|
'provincia' => 'RM',
|
|
'foglio' => '403',
|
|
'particella_catasto' => '60',
|
|
'codice_comune_catasto' => 'H501',
|
|
'codice_fiscale' => '80212560587',
|
|
'attivo' => 1,
|
|
]
|
|
);
|
|
|
|
$unit233 = UnitaImmobiliare::firstOrCreate(
|
|
['stabile_id' => $stabile0013->id, 'codice_unita' => '0013-A-1'],
|
|
[
|
|
'scala' => 'A',
|
|
'interno' => '1',
|
|
'piano' => '3',
|
|
'subalterno' => '509',
|
|
'categoria_catastale' => 'A/2',
|
|
'rendita_catastale' => 2375.70,
|
|
'sezione_urbana' => 'H501',
|
|
'numero_vani' => 9,
|
|
'stato' => 'attiva',
|
|
]
|
|
);
|
|
|
|
StabileContext::setActiveStabileId($user, $stabile0013->id);
|
|
request()->merge(['unita_id' => $unit233->id]);
|
|
|
|
$page = new CatastoHub();
|
|
$page->mount();
|
|
|
|
expect($page->stabileAttivo)->not->toBeNull()
|
|
->and($page->stabileAttivo->codice_stabile)->toBe('0013')
|
|
->and($page->stabileAttivo->foglio)->toBe('403')
|
|
->and($page->stabileAttivo->particella_catasto)->toBe('60');
|
|
|
|
expect($page->legacyData)->toBeArray()
|
|
->and($page->legacyData['foglio'])->toBe('403')
|
|
->and($page->legacyData['particella'])->toBe('60')
|
|
->and($page->legacyData['subalterno'])->toBe('509')
|
|
->and($page->legacyData['rendita'])->toBe('2.375,70');
|
|
|
|
// Sincronizzazione geometria da DB
|
|
$page->interrogaGeometriaStabile();
|
|
expect($page->stabileSubalterni)->toBeArray();
|
|
|
|
// Verify subalterno 509 exists in geometry and address does NOT contain "Viale delle Milizie"
|
|
$sub509 = collect($page->stabileSubalterni)->firstWhere('sub', '509');
|
|
expect($sub509)->not->toBeNull()
|
|
->and($sub509['indirizzo_completo'])->toContain('OTTAVIANO')
|
|
->and($sub509['indirizzo_completo'])->not->toContain('Viale delle Milizie');
|
|
});
|
|
|
|
test('sister catasto service resolves authentic credentials and builds correct api endpoints', function () {
|
|
$service = new SisterCatastoService();
|
|
$creds = $service->resolveCredentials();
|
|
|
|
expect($creds)->toBeArray()
|
|
->and($creds['passwordScript'])->toBe('nethomestore_dfgr345gd')
|
|
->and($creds['base_url'])->toContain('thenetworksolution.it');
|
|
|
|
$urlMash = $service->buildSisterUrl($creds['base_url'], 'mashIntestati.php');
|
|
$urlRicerca = $service->buildSisterUrl($creds['base_url'], 'ricercaImmobile.php');
|
|
$urlComuni = $service->buildSisterUrl($creds['base_url'], 'comuni.php');
|
|
|
|
expect($urlMash)->toBe('https://thenetworksolution.it/sister/mashIntestati.php')
|
|
->and($urlRicerca)->toBe('https://thenetworksolution.it/sister/ricercaImmobile.php')
|
|
->and($urlComuni)->toBe('https://thenetworksolution.it/sister/comuni.php');
|
|
});
|