up
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Caja;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Carbon;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\CajaController
|
||||
*/
|
||||
final class CajaControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$cajas = Caja::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('cajas.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\CajaController::class,
|
||||
'store',
|
||||
\App\Http\Requests\CajaStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$monto_inicial = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$fecha_apertura = Carbon::parse(fake()->dateTime());
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->post(route('cajas.store'), [
|
||||
'monto_inicial' => $monto_inicial,
|
||||
'fecha_apertura' => $fecha_apertura->toDateTimeString(),
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$cajas = Caja::query()
|
||||
->where('monto_inicial', $monto_inicial)
|
||||
->where('fecha_apertura', $fecha_apertura)
|
||||
->where('estado', $estado)
|
||||
->get();
|
||||
$this->assertCount(1, $cajas);
|
||||
$caja = $cajas->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$caja = Caja::factory()->create();
|
||||
|
||||
$response = $this->get(route('cajas.show', $caja));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\CajaController::class,
|
||||
'update',
|
||||
\App\Http\Requests\CajaUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$caja = Caja::factory()->create();
|
||||
$monto_inicial = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$fecha_apertura = Carbon::parse(fake()->dateTime());
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->put(route('cajas.update', $caja), [
|
||||
'monto_inicial' => $monto_inicial,
|
||||
'fecha_apertura' => $fecha_apertura->toDateTimeString(),
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$caja->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($monto_inicial, $caja->monto_inicial);
|
||||
$this->assertEquals($fecha_apertura, $caja->fecha_apertura);
|
||||
$this->assertEquals($estado, $caja->estado);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$caja = Caja::factory()->create();
|
||||
|
||||
$response = $this->delete(route('cajas.destroy', $caja));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($caja);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use App\Models\Categorium;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\CategoriaController
|
||||
*/
|
||||
final class CategoriaControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$categoria = Categoria::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('categoria.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\CategoriaController::class,
|
||||
'store',
|
||||
\App\Http\Requests\CategoriaStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$nombre = fake()->word();
|
||||
|
||||
$response = $this->post(route('categoria.store'), [
|
||||
'nombre' => $nombre,
|
||||
]);
|
||||
|
||||
$categoria = Categorium::query()
|
||||
->where('nombre', $nombre)
|
||||
->get();
|
||||
$this->assertCount(1, $categoria);
|
||||
$categorium = $categoria->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$categorium = Categoria::factory()->create();
|
||||
|
||||
$response = $this->get(route('categoria.show', $categorium));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\CategoriaController::class,
|
||||
'update',
|
||||
\App\Http\Requests\CategoriaUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$categorium = Categoria::factory()->create();
|
||||
$nombre = fake()->word();
|
||||
|
||||
$response = $this->put(route('categoria.update', $categorium), [
|
||||
'nombre' => $nombre,
|
||||
]);
|
||||
|
||||
$categorium->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($nombre, $categorium->nombre);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$categorium = Categoria::factory()->create();
|
||||
$categorium = Categorium::factory()->create();
|
||||
|
||||
$response = $this->delete(route('categoria.destroy', $categorium));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($categorium);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Cliente;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\ClienteController
|
||||
*/
|
||||
final class ClienteControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$clientes = Cliente::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('clientes.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\ClienteController::class,
|
||||
'store',
|
||||
\App\Http\Requests\ClienteStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$nombre = fake()->word();
|
||||
$tipo_documento = fake()->randomElement(/** enum_attributes **/);
|
||||
$numero_documento = fake()->word();
|
||||
|
||||
$response = $this->post(route('clientes.store'), [
|
||||
'nombre' => $nombre,
|
||||
'tipo_documento' => $tipo_documento,
|
||||
'numero_documento' => $numero_documento,
|
||||
]);
|
||||
|
||||
$clientes = Cliente::query()
|
||||
->where('nombre', $nombre)
|
||||
->where('tipo_documento', $tipo_documento)
|
||||
->where('numero_documento', $numero_documento)
|
||||
->get();
|
||||
$this->assertCount(1, $clientes);
|
||||
$cliente = $clientes->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$cliente = Cliente::factory()->create();
|
||||
|
||||
$response = $this->get(route('clientes.show', $cliente));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\ClienteController::class,
|
||||
'update',
|
||||
\App\Http\Requests\ClienteUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$cliente = Cliente::factory()->create();
|
||||
$nombre = fake()->word();
|
||||
$tipo_documento = fake()->randomElement(/** enum_attributes **/);
|
||||
$numero_documento = fake()->word();
|
||||
|
||||
$response = $this->put(route('clientes.update', $cliente), [
|
||||
'nombre' => $nombre,
|
||||
'tipo_documento' => $tipo_documento,
|
||||
'numero_documento' => $numero_documento,
|
||||
]);
|
||||
|
||||
$cliente->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($nombre, $cliente->nombre);
|
||||
$this->assertEquals($tipo_documento, $cliente->tipo_documento);
|
||||
$this->assertEquals($numero_documento, $cliente->numero_documento);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$cliente = Cliente::factory()->create();
|
||||
|
||||
$response = $this->delete(route('clientes.destroy', $cliente));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($cliente);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Compra;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Carbon;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\CompraController
|
||||
*/
|
||||
final class CompraControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$compras = Compra::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('compras.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\CompraController::class,
|
||||
'store',
|
||||
\App\Http\Requests\CompraStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$fecha = Carbon::parse(fake()->dateTime());
|
||||
$total = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->post(route('compras.store'), [
|
||||
'fecha' => $fecha->toDateTimeString(),
|
||||
'total' => $total,
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$compras = Compra::query()
|
||||
->where('fecha', $fecha)
|
||||
->where('total', $total)
|
||||
->where('estado', $estado)
|
||||
->get();
|
||||
$this->assertCount(1, $compras);
|
||||
$compra = $compras->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$compra = Compra::factory()->create();
|
||||
|
||||
$response = $this->get(route('compras.show', $compra));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\CompraController::class,
|
||||
'update',
|
||||
\App\Http\Requests\CompraUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$compra = Compra::factory()->create();
|
||||
$fecha = Carbon::parse(fake()->dateTime());
|
||||
$total = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->put(route('compras.update', $compra), [
|
||||
'fecha' => $fecha->toDateTimeString(),
|
||||
'total' => $total,
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$compra->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($fecha, $compra->fecha);
|
||||
$this->assertEquals($total, $compra->total);
|
||||
$this->assertEquals($estado, $compra->estado);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$compra = Compra::factory()->create();
|
||||
|
||||
$response = $this->delete(route('compras.destroy', $compra));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($compra);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Compra;
|
||||
use App\Models\DetalleCompra;
|
||||
use App\Models\Producto;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\DetalleCompraController
|
||||
*/
|
||||
final class DetalleCompraControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$detalleCompras = DetalleCompra::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('detalle-compras.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\DetalleCompraController::class,
|
||||
'store',
|
||||
\App\Http\Requests\DetalleCompraStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$compra = Compra::factory()->create();
|
||||
$producto = Producto::factory()->create();
|
||||
$cantidad = fake()->numberBetween(-10000, 10000);
|
||||
$precio_unitario = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$subtotal = fake()->randomFloat(/** decimal_attributes **/);
|
||||
|
||||
$response = $this->post(route('detalle-compras.store'), [
|
||||
'compra_id' => $compra->id,
|
||||
'producto_id' => $producto->id,
|
||||
'cantidad' => $cantidad,
|
||||
'precio_unitario' => $precio_unitario,
|
||||
'subtotal' => $subtotal,
|
||||
]);
|
||||
|
||||
$detalleCompras = DetalleCompra::query()
|
||||
->where('compra_id', $compra->id)
|
||||
->where('producto_id', $producto->id)
|
||||
->where('cantidad', $cantidad)
|
||||
->where('precio_unitario', $precio_unitario)
|
||||
->where('subtotal', $subtotal)
|
||||
->get();
|
||||
$this->assertCount(1, $detalleCompras);
|
||||
$detalleCompra = $detalleCompras->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$detalleCompra = DetalleCompra::factory()->create();
|
||||
|
||||
$response = $this->get(route('detalle-compras.show', $detalleCompra));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\DetalleCompraController::class,
|
||||
'update',
|
||||
\App\Http\Requests\DetalleCompraUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$detalleCompra = DetalleCompra::factory()->create();
|
||||
$compra = Compra::factory()->create();
|
||||
$producto = Producto::factory()->create();
|
||||
$cantidad = fake()->numberBetween(-10000, 10000);
|
||||
$precio_unitario = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$subtotal = fake()->randomFloat(/** decimal_attributes **/);
|
||||
|
||||
$response = $this->put(route('detalle-compras.update', $detalleCompra), [
|
||||
'compra_id' => $compra->id,
|
||||
'producto_id' => $producto->id,
|
||||
'cantidad' => $cantidad,
|
||||
'precio_unitario' => $precio_unitario,
|
||||
'subtotal' => $subtotal,
|
||||
]);
|
||||
|
||||
$detalleCompra->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($compra->id, $detalleCompra->compra_id);
|
||||
$this->assertEquals($producto->id, $detalleCompra->producto_id);
|
||||
$this->assertEquals($cantidad, $detalleCompra->cantidad);
|
||||
$this->assertEquals($precio_unitario, $detalleCompra->precio_unitario);
|
||||
$this->assertEquals($subtotal, $detalleCompra->subtotal);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$detalleCompra = DetalleCompra::factory()->create();
|
||||
|
||||
$response = $this->delete(route('detalle-compras.destroy', $detalleCompra));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($detalleCompra);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\DetalleVenta;
|
||||
use App\Models\DetalleVentum;
|
||||
use App\Models\Producto;
|
||||
use App\Models\Venta;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\DetalleVentaController
|
||||
*/
|
||||
final class DetalleVentaControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$detalleVenta = DetalleVenta::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('detalle-venta.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\DetalleVentaController::class,
|
||||
'store',
|
||||
\App\Http\Requests\DetalleVentaStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$venta = Venta::factory()->create();
|
||||
$producto = Producto::factory()->create();
|
||||
$cantidad = fake()->numberBetween(-10000, 10000);
|
||||
$precio_unitario = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$subtotal = fake()->randomFloat(/** decimal_attributes **/);
|
||||
|
||||
$response = $this->post(route('detalle-venta.store'), [
|
||||
'venta_id' => $venta->id,
|
||||
'producto_id' => $producto->id,
|
||||
'cantidad' => $cantidad,
|
||||
'precio_unitario' => $precio_unitario,
|
||||
'subtotal' => $subtotal,
|
||||
]);
|
||||
|
||||
$detalleVenta = DetalleVentum::query()
|
||||
->where('venta_id', $venta->id)
|
||||
->where('producto_id', $producto->id)
|
||||
->where('cantidad', $cantidad)
|
||||
->where('precio_unitario', $precio_unitario)
|
||||
->where('subtotal', $subtotal)
|
||||
->get();
|
||||
$this->assertCount(1, $detalleVenta);
|
||||
$detalleVentum = $detalleVenta->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$detalleVentum = DetalleVenta::factory()->create();
|
||||
|
||||
$response = $this->get(route('detalle-venta.show', $detalleVentum));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\DetalleVentaController::class,
|
||||
'update',
|
||||
\App\Http\Requests\DetalleVentaUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$detalleVentum = DetalleVenta::factory()->create();
|
||||
$venta = Venta::factory()->create();
|
||||
$producto = Producto::factory()->create();
|
||||
$cantidad = fake()->numberBetween(-10000, 10000);
|
||||
$precio_unitario = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$subtotal = fake()->randomFloat(/** decimal_attributes **/);
|
||||
|
||||
$response = $this->put(route('detalle-venta.update', $detalleVentum), [
|
||||
'venta_id' => $venta->id,
|
||||
'producto_id' => $producto->id,
|
||||
'cantidad' => $cantidad,
|
||||
'precio_unitario' => $precio_unitario,
|
||||
'subtotal' => $subtotal,
|
||||
]);
|
||||
|
||||
$detalleVentum->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($venta->id, $detalleVentum->venta_id);
|
||||
$this->assertEquals($producto->id, $detalleVentum->producto_id);
|
||||
$this->assertEquals($cantidad, $detalleVentum->cantidad);
|
||||
$this->assertEquals($precio_unitario, $detalleVentum->precio_unitario);
|
||||
$this->assertEquals($subtotal, $detalleVentum->subtotal);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$detalleVentum = DetalleVenta::factory()->create();
|
||||
$detalleVentum = DetalleVentum::factory()->create();
|
||||
|
||||
$response = $this->delete(route('detalle-venta.destroy', $detalleVentum));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($detalleVentum);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Inventario;
|
||||
use App\Models\Producto;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\InventarioController
|
||||
*/
|
||||
final class InventarioControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$inventarios = Inventario::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('inventarios.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\InventarioController::class,
|
||||
'store',
|
||||
\App\Http\Requests\InventarioStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$producto = Producto::factory()->create();
|
||||
$stock_actual = fake()->numberBetween(-10000, 10000);
|
||||
$stock_minimo = fake()->numberBetween(-10000, 10000);
|
||||
|
||||
$response = $this->post(route('inventarios.store'), [
|
||||
'producto_id' => $producto->id,
|
||||
'stock_actual' => $stock_actual,
|
||||
'stock_minimo' => $stock_minimo,
|
||||
]);
|
||||
|
||||
$inventarios = Inventario::query()
|
||||
->where('producto_id', $producto->id)
|
||||
->where('stock_actual', $stock_actual)
|
||||
->where('stock_minimo', $stock_minimo)
|
||||
->get();
|
||||
$this->assertCount(1, $inventarios);
|
||||
$inventario = $inventarios->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$inventario = Inventario::factory()->create();
|
||||
|
||||
$response = $this->get(route('inventarios.show', $inventario));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\InventarioController::class,
|
||||
'update',
|
||||
\App\Http\Requests\InventarioUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$inventario = Inventario::factory()->create();
|
||||
$producto = Producto::factory()->create();
|
||||
$stock_actual = fake()->numberBetween(-10000, 10000);
|
||||
$stock_minimo = fake()->numberBetween(-10000, 10000);
|
||||
|
||||
$response = $this->put(route('inventarios.update', $inventario), [
|
||||
'producto_id' => $producto->id,
|
||||
'stock_actual' => $stock_actual,
|
||||
'stock_minimo' => $stock_minimo,
|
||||
]);
|
||||
|
||||
$inventario->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($producto->id, $inventario->producto_id);
|
||||
$this->assertEquals($stock_actual, $inventario->stock_actual);
|
||||
$this->assertEquals($stock_minimo, $inventario->stock_minimo);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$inventario = Inventario::factory()->create();
|
||||
|
||||
$response = $this->delete(route('inventarios.destroy', $inventario));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($inventario);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Caja;
|
||||
use App\Models\MovimientoCaja;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Carbon;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\MovimientoCajaController
|
||||
*/
|
||||
final class MovimientoCajaControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$movimientoCajas = MovimientoCaja::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('movimiento-cajas.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\MovimientoCajaController::class,
|
||||
'store',
|
||||
\App\Http\Requests\MovimientoCajaStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$caja = Caja::factory()->create();
|
||||
$tipo = fake()->randomElement(/** enum_attributes **/);
|
||||
$monto = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$fecha = Carbon::parse(fake()->dateTime());
|
||||
|
||||
$response = $this->post(route('movimiento-cajas.store'), [
|
||||
'caja_id' => $caja->id,
|
||||
'tipo' => $tipo,
|
||||
'monto' => $monto,
|
||||
'fecha' => $fecha->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$movimientoCajas = MovimientoCaja::query()
|
||||
->where('caja_id', $caja->id)
|
||||
->where('tipo', $tipo)
|
||||
->where('monto', $monto)
|
||||
->where('fecha', $fecha)
|
||||
->get();
|
||||
$this->assertCount(1, $movimientoCajas);
|
||||
$movimientoCaja = $movimientoCajas->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$movimientoCaja = MovimientoCaja::factory()->create();
|
||||
|
||||
$response = $this->get(route('movimiento-cajas.show', $movimientoCaja));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\MovimientoCajaController::class,
|
||||
'update',
|
||||
\App\Http\Requests\MovimientoCajaUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$movimientoCaja = MovimientoCaja::factory()->create();
|
||||
$caja = Caja::factory()->create();
|
||||
$tipo = fake()->randomElement(/** enum_attributes **/);
|
||||
$monto = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$fecha = Carbon::parse(fake()->dateTime());
|
||||
|
||||
$response = $this->put(route('movimiento-cajas.update', $movimientoCaja), [
|
||||
'caja_id' => $caja->id,
|
||||
'tipo' => $tipo,
|
||||
'monto' => $monto,
|
||||
'fecha' => $fecha->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$movimientoCaja->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($caja->id, $movimientoCaja->caja_id);
|
||||
$this->assertEquals($tipo, $movimientoCaja->tipo);
|
||||
$this->assertEquals($monto, $movimientoCaja->monto);
|
||||
$this->assertEquals($fecha, $movimientoCaja->fecha);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$movimientoCaja = MovimientoCaja::factory()->create();
|
||||
|
||||
$response = $this->delete(route('movimiento-cajas.destroy', $movimientoCaja));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($movimientoCaja);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use App\Models\Producto;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\ProductoController
|
||||
*/
|
||||
final class ProductoControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$productos = Producto::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('productos.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\ProductoController::class,
|
||||
'store',
|
||||
\App\Http\Requests\ProductoStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$nombre = fake()->word();
|
||||
$codigo_barras = fake()->word();
|
||||
$precio_compra = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$precio_venta = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$stock = fake()->numberBetween(-10000, 10000);
|
||||
$categoria = Categoria::factory()->create();
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->post(route('productos.store'), [
|
||||
'nombre' => $nombre,
|
||||
'codigo_barras' => $codigo_barras,
|
||||
'precio_compra' => $precio_compra,
|
||||
'precio_venta' => $precio_venta,
|
||||
'stock' => $stock,
|
||||
'categoria_id' => $categoria->id,
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$productos = Producto::query()
|
||||
->where('nombre', $nombre)
|
||||
->where('codigo_barras', $codigo_barras)
|
||||
->where('precio_compra', $precio_compra)
|
||||
->where('precio_venta', $precio_venta)
|
||||
->where('stock', $stock)
|
||||
->where('categoria_id', $categoria->id)
|
||||
->where('estado', $estado)
|
||||
->get();
|
||||
$this->assertCount(1, $productos);
|
||||
$producto = $productos->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$producto = Producto::factory()->create();
|
||||
|
||||
$response = $this->get(route('productos.show', $producto));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\ProductoController::class,
|
||||
'update',
|
||||
\App\Http\Requests\ProductoUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$producto = Producto::factory()->create();
|
||||
$nombre = fake()->word();
|
||||
$codigo_barras = fake()->word();
|
||||
$precio_compra = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$precio_venta = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$stock = fake()->numberBetween(-10000, 10000);
|
||||
$categoria = Categoria::factory()->create();
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->put(route('productos.update', $producto), [
|
||||
'nombre' => $nombre,
|
||||
'codigo_barras' => $codigo_barras,
|
||||
'precio_compra' => $precio_compra,
|
||||
'precio_venta' => $precio_venta,
|
||||
'stock' => $stock,
|
||||
'categoria_id' => $categoria->id,
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$producto->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($nombre, $producto->nombre);
|
||||
$this->assertEquals($codigo_barras, $producto->codigo_barras);
|
||||
$this->assertEquals($precio_compra, $producto->precio_compra);
|
||||
$this->assertEquals($precio_venta, $producto->precio_venta);
|
||||
$this->assertEquals($stock, $producto->stock);
|
||||
$this->assertEquals($categoria->id, $producto->categoria_id);
|
||||
$this->assertEquals($estado, $producto->estado);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$producto = Producto::factory()->create();
|
||||
|
||||
$response = $this->delete(route('productos.destroy', $producto));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($producto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Proveedor;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\ProveedorController
|
||||
*/
|
||||
final class ProveedorControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$proveedors = Proveedor::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('proveedors.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\ProveedorController::class,
|
||||
'store',
|
||||
\App\Http\Requests\ProveedorStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$nombre = fake()->word();
|
||||
|
||||
$response = $this->post(route('proveedors.store'), [
|
||||
'nombre' => $nombre,
|
||||
]);
|
||||
|
||||
$proveedors = Proveedor::query()
|
||||
->where('nombre', $nombre)
|
||||
->get();
|
||||
$this->assertCount(1, $proveedors);
|
||||
$proveedor = $proveedors->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$proveedor = Proveedor::factory()->create();
|
||||
|
||||
$response = $this->get(route('proveedors.show', $proveedor));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\ProveedorController::class,
|
||||
'update',
|
||||
\App\Http\Requests\ProveedorUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$proveedor = Proveedor::factory()->create();
|
||||
$nombre = fake()->word();
|
||||
|
||||
$response = $this->put(route('proveedors.update', $proveedor), [
|
||||
'nombre' => $nombre,
|
||||
]);
|
||||
|
||||
$proveedor->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($nombre, $proveedor->nombre);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$proveedor = Proveedor::factory()->create();
|
||||
|
||||
$response = $this->delete(route('proveedors.destroy', $proveedor));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($proveedor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\SettingController
|
||||
*/
|
||||
final class SettingControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$settings = Setting::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('settings.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\SettingController::class,
|
||||
'store',
|
||||
\App\Http\Requests\SettingStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$response = $this->post(route('settings.store'));
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertDatabaseHas(settings, [ /* ... */ ]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$setting = Setting::factory()->create();
|
||||
|
||||
$response = $this->get(route('settings.show', $setting));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\SettingController::class,
|
||||
'update',
|
||||
\App\Http\Requests\SettingUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$setting = Setting::factory()->create();
|
||||
|
||||
$response = $this->put(route('settings.update', $setting));
|
||||
|
||||
$setting->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$setting = Setting::factory()->create();
|
||||
|
||||
$response = $this->delete(route('settings.destroy', $setting));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($setting);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Models\Venta;
|
||||
use App\Models\Ventum;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Carbon;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\VentaController
|
||||
*/
|
||||
final class VentaControllerTest extends TestCase
|
||||
{
|
||||
use AdditionalAssertions, RefreshDatabase, WithFaker;
|
||||
|
||||
#[Test]
|
||||
public function index_behaves_as_expected(): void
|
||||
{
|
||||
$venta = Venta::factory()->count(3)->create();
|
||||
|
||||
$response = $this->get(route('venta.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function store_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\VentaController::class,
|
||||
'store',
|
||||
\App\Http\Requests\VentaStoreRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_saves(): void
|
||||
{
|
||||
$fecha = Carbon::parse(fake()->dateTime());
|
||||
$total = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$tipo_pago = fake()->randomElement(/** enum_attributes **/);
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->post(route('venta.store'), [
|
||||
'fecha' => $fecha->toDateTimeString(),
|
||||
'total' => $total,
|
||||
'tipo_pago' => $tipo_pago,
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$venta = Ventum::query()
|
||||
->where('fecha', $fecha)
|
||||
->where('total', $total)
|
||||
->where('tipo_pago', $tipo_pago)
|
||||
->where('estado', $estado)
|
||||
->get();
|
||||
$this->assertCount(1, $venta);
|
||||
$ventum = $venta->first();
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function show_behaves_as_expected(): void
|
||||
{
|
||||
$ventum = Venta::factory()->create();
|
||||
|
||||
$response = $this->get(route('venta.show', $ventum));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function update_uses_form_request_validation(): void
|
||||
{
|
||||
$this->assertActionUsesFormRequest(
|
||||
\App\Http\Controllers\VentaController::class,
|
||||
'update',
|
||||
\App\Http\Requests\VentaUpdateRequest::class
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_behaves_as_expected(): void
|
||||
{
|
||||
$ventum = Venta::factory()->create();
|
||||
$fecha = Carbon::parse(fake()->dateTime());
|
||||
$total = fake()->randomFloat(/** decimal_attributes **/);
|
||||
$tipo_pago = fake()->randomElement(/** enum_attributes **/);
|
||||
$estado = fake()->randomElement(/** enum_attributes **/);
|
||||
|
||||
$response = $this->put(route('venta.update', $ventum), [
|
||||
'fecha' => $fecha->toDateTimeString(),
|
||||
'total' => $total,
|
||||
'tipo_pago' => $tipo_pago,
|
||||
'estado' => $estado,
|
||||
]);
|
||||
|
||||
$ventum->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([]);
|
||||
|
||||
$this->assertEquals($fecha, $ventum->fecha);
|
||||
$this->assertEquals($total, $ventum->total);
|
||||
$this->assertEquals($tipo_pago, $ventum->tipo_pago);
|
||||
$this->assertEquals($estado, $ventum->estado);
|
||||
}
|
||||
|
||||
|
||||
#[Test]
|
||||
public function destroy_deletes_and_responds_with(): void
|
||||
{
|
||||
$ventum = Venta::factory()->create();
|
||||
$ventum = Ventum::factory()->create();
|
||||
|
||||
$response = $this->delete(route('venta.destroy', $ventum));
|
||||
|
||||
$response->assertNoContent();
|
||||
|
||||
$this->assertModelMissing($ventum);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user