From 360537c6385ba508321ee26259529f45e84a006c Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 24 Jun 2025 14:24:47 -0400 Subject: [PATCH] Prueba de integracion para service worker --- app/resources/database/seeds/Comuna.php | 391 ++++++++++++++++++++++++ app/tests/integration/QueueTest.php | 50 +++ 2 files changed, 441 insertions(+) create mode 100644 app/resources/database/seeds/Comuna.php diff --git a/app/resources/database/seeds/Comuna.php b/app/resources/database/seeds/Comuna.php new file mode 100644 index 0000000..b77de3f --- /dev/null +++ b/app/resources/database/seeds/Comuna.php @@ -0,0 +1,391 @@ +execute('SET unique_checks=0; SET foreign_key_checks=0;'); + + $table = $this->table('comuna'); + $table->truncate(); + + $data = [ + ['id' => 1101, 'descripcion' => 'Iquique', 'provincia' => 11], + ['id' => 1107, 'descripcion' => 'Alto Hospicio', 'provincia' => 11], + ['id' => 1401, 'descripcion' => 'Pozo Almonte', 'provincia' => 14], + ['id' => 1402, 'descripcion' => 'Camiña', 'provincia' => 14], + ['id' => 1403, 'descripcion' => 'Colchane', 'provincia' => 14], + ['id' => 1404, 'descripcion' => 'Huara', 'provincia' => 14], + ['id' => 1405, 'descripcion' => 'Pica', 'provincia' => 14], + ['id' => 2101, 'descripcion' => 'Antofagasta', 'provincia' => 21], + ['id' => 2102, 'descripcion' => 'Mejillones', 'provincia' => 21], + ['id' => 2103, 'descripcion' => 'Sierra Gorda', 'provincia' => 21], + ['id' => 2104, 'descripcion' => 'Taltal', 'provincia' => 21], + ['id' => 2201, 'descripcion' => 'Calama', 'provincia' => 22], + ['id' => 2202, 'descripcion' => 'Ollagüe', 'provincia' => 22], + ['id' => 2203, 'descripcion' => 'San Pedro de Alcántara', 'provincia' => 22], + ['id' => 2301, 'descripcion' => 'Tocopilla', 'provincia' => 23], + ['id' => 2302, 'descripcion' => 'María Elena', 'provincia' => 23], + ]; + } +} diff --git a/app/tests/integration/QueueTest.php b/app/tests/integration/QueueTest.php index dda22b9..6901382 100644 --- a/app/tests/integration/QueueTest.php +++ b/app/tests/integration/QueueTest.php @@ -3,6 +3,7 @@ namespace Incoviba\Test\Integration; use Psr\Container\ContainerInterface; use PHPUnit\Framework\TestCase; +use Faker; use Incoviba\Common\Implement; use Incoviba\Common\Ideal; use Incoviba\Service; @@ -20,6 +21,7 @@ class QueueTest extends TestCase public function testServiceWorker(): void { + $faker = Faker\Factory::create(); $pagoData = [ 'fecha' => '2022-01-01', 'valor' => 10000, @@ -27,10 +29,58 @@ class QueueTest extends TestCase $pagoService = $this->container->get(Service\Venta\Pago::class); $pago = $pagoService->add($pagoData); + $this->assertEquals(0.0, $pago->uf); + $queueService = $this->container->get(Service\Queue::class); $queueService->run(); $pago = $pagoService->getById($pago->id); $this->assertNotEquals(0.0, $pago->uf); + + $comunaRepository = $this->container->get(Repository\Comuna::class); + $comunas = $comunaRepository->fetchAll(); + $id = $faker->numberBetween(0, count($comunas) - 1); + $comuna = $comunas[$id]; + $direccionData = [ + 'calle' => $faker->streetName, + 'numero' => $faker->buildingNumber, + 'comuna' => $comuna->id + ]; + $propietarioData = [ + 'rut' => $faker->numberBetween(10000000, 99999999), + 'nombre' => $faker->name, + 'apellido_paterno' => $faker->lastName, + 'apellido_materno' => $faker->lastName, + ]; + $propietarioRepository = $this->container->get(Repository\Venta\Propietario::class); + $propietario = $propietarioRepository->create($propietarioData); + $propietario = $propietarioRepository->save($propietario); + $propiedadRepository = $this->container->get(Repository\Venta\Propiedad::class); + $propiedad = $propiedadRepository->create(); + $propiedad = $propiedadRepository->save($propiedad); + $ventaData = [ + 'fecha' => '2022-01-01', + 'propietario' => $propietario->rut, + 'propiedad' => $propiedad->id, + ]; + $ventaRepository = $this->container->get(Repository\Venta::class); + $venta = $ventaRepository->create($ventaData); + $venta = $ventaRepository->save($venta); + + $cuotaData = [ + 'venta' => $venta->id, + 'fecha' => '2022-01-01', + 'valor' => 10000, + ]; + $cuotaService = $this->container->get(Service\Venta\Cuota::class); + $cuota = $cuotaService->add($cuotaData); + + $this->assertEquals(0.0, $cuota->pago->uf); + + $queueService = $this->container->get(Service\Queue::class); + $queueService->run(); + + $cuota = $cuotaService->getById($cuota->id); + $this->assertNotEquals(0.0, $cuota->pago->uf); } } \ No newline at end of file