up
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\Models\Proveedor;
|
||||
use App\Models\OrdenProduccion;
|
||||
use App\Models\Confeccion;
|
||||
use App\Models\Prensilla;
|
||||
use App\Models\Ojal;
|
||||
use App\Models\Recepcion;
|
||||
|
||||
class PrensillaOjalTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_cannot_assign_more_than_available_from_confecciones()
|
||||
{
|
||||
$prov = Proveedor::create(['nombre' => 'P', 'nit' => '00', 'categoria' => 'prensilla']);
|
||||
$prov2 = Proveedor::create(['nombre' => 'O', 'nit' => '01', 'categoria' => 'ojal']);
|
||||
$op = OrdenProduccion::create(['prenda_modelo' => 'X', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
// Crear confecciones y recepciones para generar 50 unidades
|
||||
$conf = Confeccion::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 50, 'valor_por_prenda' => 0]);
|
||||
Recepcion::create(['referencia_type' => Confeccion::class, 'referencia_id' => $conf->id, 'cantidad' => 50]);
|
||||
|
||||
$this->assertEquals(50, $conf->recibido_total);
|
||||
|
||||
// Asignar 30 a prensilla y 20 a ojal => OK
|
||||
Prensilla::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 30]);
|
||||
Ojal::create(['proveedor_id' => $prov2->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 20]);
|
||||
|
||||
$this->assertDatabaseHas('prensillas', ['orden_produccion_id' => $op->id, 'cantidad_enviada' => 30]);
|
||||
$this->assertDatabaseHas('ojales', ['orden_produccion_id' => $op->id, 'cantidad_enviada' => 20]);
|
||||
|
||||
// Ahora intentar asignar 1 adicional en prensilla debe fallar (excede 50)
|
||||
$this->expectException(\Illuminate\Validation\ValidationException::class);
|
||||
Prensilla::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 1]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user