Files
kreios/backoffice/tests/Feature/CatalogoApiTest.php
T
carmine.savino 0dfda3a338 Refactor PVC models and update tests
- Updated the PVC models in the database and adjusted the tests accordingly to reflect the new model counts and codes.
- Removed deprecated models from the JSON data for PVC systems.
- Added new GLB models for "scorrevole_sf_3_ante" and "scorrevole_sf_4_ante".
- Enhanced the development scripts to streamline the build process for both frontends.
- Updated documentation to reflect changes in the development environment and deployment process.
- Improved the styling of texture radio options for better visibility.
- Fixed URL handling in the configurator to ensure proper routing and API calls.
2026-10-20 18:40:59 +02:00

83 lines
3.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\ListinoPrezzo;
use App\Models\Modello;
use App\Models\Sistema;
use Database\Seeders\CatalogoSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class CatalogoApiTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('public');
}
public function test_il_seeder_carica_anagrafica_pvc_con_icone(): void
{
$this->seed(CatalogoSeeder::class);
$pvc = Sistema::where('codice', 'pvc')->firstOrFail();
$this->assertSame(28, $pvc->modelli()->count());
$finestra = $pvc->modelli()->where('codice', 'finestra_1_anta')->firstOrFail();
$this->assertSame('FINESTRA 1 ANTA, A/R', $finestra->descrizione);
Storage::disk('public')->assertExists($finestra->icona);
// Modelli presenti solo nell'Excel: senza asset 3D, quindi disattivi.
$this->assertFalse($pvc->modelli()->where('codice', 'scorrevole_hst_4_ante')->value('attivo'));
}
public function test_il_seeder_non_sovrascrive_le_modifiche_admin(): void
{
$this->seed(CatalogoSeeder::class);
Modello::where('codice', 'bilico')->update(['nome' => 'Bilico modificato']);
$this->seed(CatalogoSeeder::class);
$this->assertSame('Bilico modificato', Modello::where('codice', 'bilico')->value('nome'));
$this->assertSame(28, Modello::count());
}
public function test_api_sistemi_espone_solo_modelli_attivi_e_con_listino_in_ordine(): void
{
$this->seed(CatalogoSeeder::class);
// Senza listino il bilico non compare nel configuratore.
Modello::where('codice', '!=', 'bilico')->each(fn (Modello $m) => ListinoPrezzo::create(['modello_id' => $m->id, 'larghezza' => 1000, 'altezza' => 1000, 'prezzo' => 100]));
Sistema::create(['codice' => 'legno', 'nome' => 'Legno', 'attivo' => false]);
$response = $this->getJson('/api/sistemi')->assertOk();
$response->assertJsonCount(1);
$response->assertJsonPath('0.codice', 'pvc');
$modelli = collect($response->json('0.modelli'));
$this->assertSame(25, $modelli->count());
$this->assertNotContains('bilico', $modelli->pluck('id'));
$this->assertSame('finestra_1_anta', $modelli->first()['id']);
$this->assertNotContains('scorrevole_hst_4_ante', $modelli->pluck('id'));
$this->assertStringEndsWith('/storage/modelli/icone/pvc/finestra_1_anta.jpg', $modelli->first()['icona']);
$this->assertSame('finestra_1_anta.glb', $modelli->first()['modello']);
}
public function test_configurazione_di_un_modello_senza_listino_restituisce_404(): void
{
$this->seed(CatalogoSeeder::class);
$this->getJson('/api/sistemi/pvc/modelli/bilico/configurazione')->assertNotFound();
}
public function test_api_sistema_inesistente_restituisce_404(): void
{
$this->getJson('/api/sistemi/inesistente')->assertNotFound();
}
}