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('unita immobiliare page mounts without 500 or undefined property exception when canale_convocazione is null or missing', function () { $user = User::first(); if (! $user) { $user = User::factory()->create(); } expect($user)->not->toBeNull(); // Assign admin role if Spatie permissions are present 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(); Auth::login($user); // Unit 13 is Scala A Int 11 (0021-A-11) $unit = UnitaImmobiliare::where('stabile_id', $stabile->id)->where('scala', 'A')->where('interno', '11')->first(); expect($unit)->not->toBeNull(); request()->merge(['unita_id' => $unit->id]); $page = new UnitaImmobiliarePage(); // Verify mount executes without any Undefined property exception or error $page->mount(); expect($page->canaliComunicazione)->toBeArray(); expect(count($page->canaliComunicazione))->toBeGreaterThan(0); foreach ($page->canaliComunicazione as $item) { expect($item)->toHaveKeys(['id', 'nominativo', 'codice_fiscale', 'convocazione', 'verbali', 'solleciti']); expect($item['convocazione'])->not->toBeNull(); } }); test('unita 13 (0021-A-11) timeline preserves ATER historical and Benedetto Daniela current', function () { $stabile = Stabile::where('codice_stabile', '0021')->first(); expect($stabile)->not->toBeNull(); $unit = UnitaImmobiliare::where('stabile_id', $stabile->id)->where('scala', 'A')->where('interno', '11')->first(); expect($unit)->not->toBeNull(); $rels = DB::table('persone_unita_relazioni')->where('unita_id', $unit->id)->get(); expect($rels->count())->toBeGreaterThanOrEqual(2); $aterRel = $rels->firstWhere('attivo', 0); expect($aterRel)->not->toBeNull(); $benedettoRel = $rels->firstWhere('attivo', 1); expect($benedettoRel)->not->toBeNull(); $benedettoPerson = DB::table('persone')->where('id', $benedettoRel->persona_id)->first(); expect($benedettoPerson->cognome)->toBe('BENEDETTO'); expect($benedettoPerson->nome)->toBe('DANIELA'); });