Skip to content

Commit ecd3317

Browse files
committed
Feature: Test aplicados a moduolos inventarios
1 parent 4f8884c commit ecd3317

8 files changed

Lines changed: 1087 additions & 0 deletions
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
namespace Tests\Feature\Inventario;
4+
5+
use Tests\TestCase;
6+
use Illuminate\Support\Facades\Http;
7+
use PHPUnit\Framework\Attributes\Test;
8+
9+
class PedidosProveedoresControllerTest extends TestCase
10+
{
11+
// ===========================================
12+
// GET /inventario/pedidos-proveedores -> index
13+
// ===========================================
14+
15+
#[Test]
16+
public function index_maneja_error_de_api_pedidos_correctamente(): void
17+
{
18+
Http::fake([
19+
'*/pedido/proveedores' => Http::response(['error' => 'API Error'], 500),
20+
'*/proveedores' => Http::response([], 200),
21+
'*/ingredientes/lista' => Http::response([], 200)
22+
]);
23+
24+
$response = $this->get(route('pedidoproveedores.index'));
25+
26+
$response->assertStatus(200);
27+
$response->assertViewIs('inventarioviews.pedidoproveedores.index');
28+
$response->assertViewHas('pedidos', []);
29+
$response->assertViewHas('error');
30+
}
31+
32+
// ===========================================
33+
// POST /inventario/pedidos-proveedores/store -> store
34+
// ===========================================
35+
36+
#[Test]
37+
public function store_falla_validacion_si_faltan_campos_requeridos(): void
38+
{
39+
$response = $this->post(route('pedidoproveedores.store'), []);
40+
41+
$response->assertSessionHasErrors([
42+
'idProveedor',
43+
'numeroPedido',
44+
'estadoPedido',
45+
'detalles'
46+
]);
47+
}
48+
49+
// ===========================================
50+
// GET /inventario/pedidos-proveedores/show/{id} -> show
51+
// ===========================================
52+
53+
#[Test]
54+
public function show_redirige_si_falla_la_api(): void
55+
{
56+
Http::fake([
57+
'*/pedido/proveedores/99' => Http::response('Not Found', 404)
58+
]);
59+
60+
$response = $this->get(route('pedidoproveedores.show', ['id' => 99]));
61+
62+
$response->assertRedirect(route('pedidoproveedores.index'));
63+
$response->assertSessionHas('error');
64+
}
65+
66+
// ===========================================
67+
// PUT /inventario/pedidos-proveedores/update/{id} -> update
68+
// ===========================================
69+
70+
#[Test]
71+
public function update_actualiza_encabezado_y_redirige_con_success(): void
72+
{
73+
Http::fake([
74+
'*/pedido/proveedores/1' => Http::response('Actualizado', 200)
75+
]);
76+
77+
$response = $this->put(route('pedidoproveedores.update', ['id' => 1]), [
78+
'idProveedor' => 2,
79+
'numeroPedido' => 1005,
80+
'estadoPedido' => 'Enviado'
81+
]);
82+
83+
$response->assertRedirect(route('pedidoproveedores.index'));
84+
}
85+
86+
// ===========================================
87+
// DELETE /inventario/pedidos-proveedores/delete/{id} -> destroy
88+
// ===========================================
89+
90+
#[Test]
91+
public function destroy_elimina_pedido_y_redirige_con_success(): void
92+
{
93+
Http::fake([
94+
'*/pedido/proveedores/1' => Http::response('Eliminado', 200)
95+
]);
96+
97+
$response = $this->delete(route('pedidoproveedores.destroy', ['id' => 1]));
98+
99+
$response->assertRedirect(route('pedidoproveedores.index'));
100+
}
101+
102+
// ===========================================
103+
// PATCH /inventario/pedidos-proveedores/{id}/entregar -> entregar
104+
// ===========================================
105+
106+
#[Test]
107+
public function entregar_marca_pedido_como_entregado_y_redirige_con_success(): void
108+
{
109+
Http::fake([
110+
'*/pedido/proveedores/1/entregar' => Http::response('Entregado', 200)
111+
]);
112+
113+
$response = $this->patch(route('pedidoproveedores.entregar', ['id' => 1]));
114+
115+
$response->assertRedirect(route('pedidoproveedores.index'));
116+
$response->assertSessionHas('success');
117+
}
118+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
3+
namespace Tests\Feature\Inventario;
4+
5+
use Tests\TestCase;
6+
use Illuminate\Support\Facades\Http;
7+
use PHPUnit\Framework\Attributes\Test;
8+
9+
class ProduccionControllerTest extends TestCase
10+
{
11+
// ===========================================
12+
// GET /inventario/produccion -> index
13+
// ===========================================
14+
15+
#[Test]
16+
public function index_retorna_200_con_historial_y_recetas(): void
17+
{
18+
Http::fake([
19+
'*/inventario/produccion' => Http::response([
20+
[
21+
'idProduccion' => 1,
22+
'idProducto' => 1,
23+
'cantidadProducida' => 10,
24+
'fechaProduccion' => '2023-10-01'
25+
]
26+
], 200),
27+
'*/inventario/recetas/optimizadas' => Http::response([
28+
[
29+
'idProducto' => 1,
30+
'nombreProducto' => 'Pan Frances',
31+
'idIngrediente' => 2,
32+
'cantidadRequerida' => 500,
33+
'idUnidad' => 1
34+
]
35+
], 200)
36+
]);
37+
38+
$response = $this->get(route('produccion.index'));
39+
40+
$response->assertStatus(200);
41+
$response->assertViewIs('inventarioviews.produccion.index');
42+
$response->assertViewHas('historial');
43+
$response->assertViewHas('productosConReceta');
44+
$response->assertViewHas('recetas');
45+
}
46+
47+
#[Test]
48+
public function index_maneja_error_y_devuelve_vista_con_array_vacio(): void
49+
{
50+
Http::fake([
51+
'*/inventario/produccion' => Http::response('Server Error', 500),
52+
'*/inventario/recetas/optimizadas' => Http::response('Server Error', 500)
53+
]);
54+
55+
$response = $this->get(route('produccion.index'));
56+
57+
$response->assertStatus(200);
58+
$response->assertViewIs('inventarioviews.produccion.index');
59+
$response->assertViewHas('historial', []);
60+
$response->assertViewHas('recetas', []);
61+
$response->assertViewHas('error');
62+
}
63+
64+
// ===========================================
65+
// POST /inventario/produccion/store -> store
66+
// ===========================================
67+
68+
#[Test]
69+
public function store_falla_validacion_si_faltan_campos_requeridos(): void
70+
{
71+
$response = $this->post(route('produccion.store'), []);
72+
73+
$response->assertSessionHasErrors([
74+
'idProducto',
75+
'cantidadProducida'
76+
]);
77+
}
78+
79+
#[Test]
80+
public function store_registra_produccion_exitosamente(): void
81+
{
82+
Http::fake([
83+
'*/inventario/produccion' => Http::response([
84+
'mensaje' => 'Producción registrada',
85+
'idProduccion' => 100
86+
], 200)
87+
]);
88+
89+
$response = $this->post(route('produccion.store'), [
90+
'idProducto' => 1,
91+
'cantidadProducida' => 20.5
92+
]);
93+
94+
$response->assertRedirect(route('produccion.index'));
95+
$response->assertSessionHas('success');
96+
}
97+
98+
#[Test]
99+
public function store_falla_cuando_api_rechaza(): void
100+
{
101+
Http::fake([
102+
'*/inventario/produccion' => Http::response(['error' => 'Sin ingredientes'], 400)
103+
]);
104+
105+
$response = $this->post(route('produccion.store'), [
106+
'idProducto' => 1,
107+
'cantidadProducida' => 20.5
108+
]);
109+
110+
$response->assertRedirect();
111+
$response->assertSessionHas('error');
112+
}
113+
114+
// ===========================================
115+
// DELETE /inventario/produccion/delete/{id} -> destroy
116+
// ===========================================
117+
118+
#[Test]
119+
public function destroy_elimina_produccion_exitosamente(): void
120+
{
121+
Http::fake([
122+
'*/inventario/produccion/1' => Http::response('', 204)
123+
]);
124+
125+
$response = $this->delete(route('produccion.destroy', ['id' => 1]));
126+
127+
$response->assertRedirect(route('produccion.index'));
128+
$response->assertSessionHas('success');
129+
}
130+
131+
#[Test]
132+
public function destroy_falla_cuando_api_retorna_error(): void
133+
{
134+
Http::fake([
135+
'*/inventario/produccion/99' => Http::response(['error' => 'No encontrado'], 404)
136+
]);
137+
138+
$response = $this->delete(route('produccion.destroy', ['id' => 99]));
139+
140+
$response->assertRedirect();
141+
$response->assertSessionHas('error');
142+
}
143+
}

0 commit comments

Comments
 (0)