Files
pos_heidiver/tests/Feature/OrdenProduccionTelaReservationTest.php
2026-01-19 19:42:05 -05:00

62 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Models\OrdenProduccion;
use App\Models\Tela;
class OrdenProduccionTelaReservationTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function it_reserves_tela_metros_when_created_in_en_corte()
{
$tela = Tela::create([
'nombre' => 'Tela A',
'metros_disponibles' => 100,
]);
$orden = OrdenProduccion::create([
'prenda_modelo' => 'Camisa X',
'referencia' => 'REF-1',
'cantidad_total' => 10,
'tela_id' => $tela->id,
'metros_requeridos' => 30,
'estado' => 'en_corte',
'fecha_inicio' => now()->toDateString(),
'fecha_entrega_estimada' => now()->addDays(7)->toDateString(),
]);
$tela->refresh();
$this->assertEquals(70, $tela->metros_disponibles);
$orden->refresh();
$this->assertTrue((bool) $orden->tela_reservada);
}
/** @test */
public function it_fails_if_not_enough_meters_on_create()
{
$this->expectException(\Illuminate\Validation\ValidationException::class);
$tela = Tela::create([
'nombre' => 'Tela B',
'metros_disponibles' => 20,
]);
OrdenProduccion::create([
'prenda_modelo' => 'Pantalon Y',
'referencia' => 'REF-2',
'cantidad_total' => 5,
'tela_id' => $tela->id,
'metros_requeridos' => 30,
'estado' => 'en_corte',
'fecha_inicio' => now()->toDateString(),
'fecha_entrega_estimada' => now()->addDays(7)->toDateString(),
]);
}
}