40 lines
2.4 KiB
PHP
40 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Tests\TestCase;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use App\Models\OrdenProduccion;
|
|
use App\Models\InventarioPrenda;
|
|
use App\Models\Producto;
|
|
|
|
class InventarioPrendaProductSyncTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_creating_inventory_populates_product_from_op()
|
|
{
|
|
$producto = Producto::create(['nombre' => 'ProdA', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => \App\Models\Categoria::create(['nombre' => 'Ropa'])->id, 'imagen' => '']);
|
|
|
|
$op = OrdenProduccion::create(['numero_orden' => 'OP-100', 'prenda_modelo' => 'ProdA', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7), 'producto_id' => $producto->id]);
|
|
|
|
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega']);
|
|
|
|
$this->assertNotNull($inv->producto_id);
|
|
$this->assertEquals($producto->id, $inv->producto_id);
|
|
}
|
|
|
|
public function test_creating_inventory_throws_if_product_differs_from_op()
|
|
{
|
|
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
|
|
$p1 = Producto::create(['nombre' => 'P1', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
|
|
$p2 = Producto::create(['nombre' => 'P2', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
|
|
|
|
$op = OrdenProduccion::create(['numero_orden' => 'OP-101', 'prenda_modelo' => 'P1', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7), 'producto_id' => $p1->id]);
|
|
|
|
$this->expectException(\Illuminate\Validation\ValidationException::class);
|
|
|
|
InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 3, 'cantidad_disponible' => 3, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $p2->id]);
|
|
}
|
|
}
|