From c220e7438bbfdfb0a50b9e172aa773f5f6c47f32 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 29 Aug 2025 18:33:30 -0400 Subject: [PATCH] Pruebas y chequeos --- app/src/Repository/Venta/Reservation.php | 4 +- .../Repository/Venta/Reservation/State.php | 3 +- app/src/Service/Venta/Reservation.php | 2 + .../API/Ventas/ReservationTest.php | 47 +++++++++++++++++-- .../src/Service/Venta/ReservationTest.php | 7 ++- 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/app/src/Repository/Venta/Reservation.php b/app/src/Repository/Venta/Reservation.php index cad55a2..5aad21f 100644 --- a/app/src/Repository/Venta/Reservation.php +++ b/app/src/Repository/Venta/Reservation.php @@ -82,7 +82,9 @@ class Reservation extends Common\Ideal\Repository $model = parent::load($data_row); $this->fetchUnits($model, $data_row); - $this->fetchBroker($model, $data_row); + try { + $this->fetchBroker($model, $data_row); + } catch (Common\Implement\Exception\EmptyResult) {} $this->fetchPromotions($model, $data_row); return $model; } diff --git a/app/src/Repository/Venta/Reservation/State.php b/app/src/Repository/Venta/Reservation/State.php index 802547c..841a849 100644 --- a/app/src/Repository/Venta/Reservation/State.php +++ b/app/src/Repository/Venta/Reservation/State.php @@ -7,7 +7,8 @@ use Incoviba\Repository; class State extends Common\Ideal\Repository { - public function __construct(Common\Define\Connection $connection, protected Repository\Venta\Reservation $reservationRepository) + public function __construct(Common\Define\Connection $connection, + protected Repository\Venta\Reservation $reservationRepository) { parent::__construct($connection); } diff --git a/app/src/Service/Venta/Reservation.php b/app/src/Service/Venta/Reservation.php index 3ebb484..4f9c713 100644 --- a/app/src/Service/Venta/Reservation.php +++ b/app/src/Service/Venta/Reservation.php @@ -190,6 +190,7 @@ class Reservation extends Ideal\Service\API } protected function addUnits(Model\Venta\Reservation $reservation, array $units): void { + //var_dump(__LINE__, $units); foreach ($units as $unit_id => $value) { try { $unit = $this->unitService->getById($unit_id); @@ -202,6 +203,7 @@ class Reservation extends Ideal\Service\API } protected function addPromotions(Model\Venta\Reservation $reservation, array $promotions): void { + var_dump(__LINE__, $promotions); foreach ($promotions as $promotion_id) { try { $promotion = $this->promotionService->getById($promotion_id); diff --git a/app/tests/integration/API/Ventas/ReservationTest.php b/app/tests/integration/API/Ventas/ReservationTest.php index e5d3db9..ba60aac 100644 --- a/app/tests/integration/API/Ventas/ReservationTest.php +++ b/app/tests/integration/API/Ventas/ReservationTest.php @@ -27,13 +27,37 @@ class ReservationTest extends TestCase $projects = $this->container->get(Repository\Proyecto::class)->fetchAll(); $project = $faker->randomElement($projects); $unitTypes = $this->container->get(Repository\Proyecto\TipoUnidad::class)->fetchAll(); + $projectUnitTypeRepository = $this->container->get(Repository\Proyecto\ProyectoTipoUnidad::class); + + $projectUnitTypes = []; + foreach ($unitTypes as $unitType) { + $ptuCount = $faker->numberBetween(1, 10); + + for ($i = 0; $i < $ptuCount; $i++) { + $ptuData = [ + 'tipo' => $unitType->id, + 'proyecto' => $project->id, + 'descripcion' => $faker->word, + ]; + $ptu = $projectUnitTypeRepository->create($ptuData); + $ptu = $projectUnitTypeRepository->save($ptu); + $projectUnitTypes[] = $ptu; + } + } + $unitsRepository = $this->container->get(Repository\Venta\Unidad::class); + $units = []; $unitsValue = []; $unitsCount = $faker->numberBetween(1, 3); for ($i = 0; $i < $unitsCount; $i++) { - $type = $faker->randomElement($unitTypes); - $units[] = $unitsRepository->fetchByProyectoAndTipo($project->id, $type->id); + $type = $faker->randomElement($projectUnitTypes); + $unitData = [ + 'pt' => $type->id, + ]; + $unit = $unitsRepository->create($unitData); + $unit = $unitsRepository->save($unit); + $units[] = $unit->id; $unitsValue[] = $faker->randomFloat(2, 1000, 10000); } @@ -68,7 +92,24 @@ class ReservationTest extends TestCase } $contracts = $this->container->get(Repository\Proyecto\Broker\Contract::class)->fetchActiveByProject($project->id); $broker = $faker->boolean(10) ? $faker->randomElement($contracts)->broker : null; - $activePromotions = $this->container->get(Repository\Venta\Promotion::class)->fetchActiveByProject($project->id); + + $promotionTypes = Model\Venta\Promotion\Type::cases(); + $promotionsRepository = $this->container->get(Repository\Venta\Promotion::class); + for ($i = 0; $i < 10; $i ++) { + $promotionData = [ + 'project_id' => $project->id, + 'type' => $faker->randomElement($promotionTypes)->value, + 'state' => Model\Venta\Promotion\State::ACTIVE->value, + 'start_date' => $faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'), + 'end_date' => $faker->dateTimeBetween('now', '+2 years')->format('Y-m-d'), + 'valid_until' => $faker->dateTimeBetween('now', '+2 years')->format('Y-m-d'), + 'amount' => $faker->randomFloat(2, 0, 1), + ]; + $promotion = $promotionsRepository->create($promotionData); + $promotionsRepository->save($promotion); + } + $activePromotions = $promotionsRepository->fetchActiveByProject($project->id); + var_dump(__LINE__, $activePromotions); $promotionsCount = $faker->numberBetween(0, 3); $promotions = []; for ($i = 0; $i < $promotionsCount; $i++) { diff --git a/app/tests/unit/src/Service/Venta/ReservationTest.php b/app/tests/unit/src/Service/Venta/ReservationTest.php index 0ef2dd2..14308c4 100644 --- a/app/tests/unit/src/Service/Venta/ReservationTest.php +++ b/app/tests/unit/src/Service/Venta/ReservationTest.php @@ -58,6 +58,11 @@ class ReservationTest extends TestCase ->disableOriginalConstructor()->getMock(); $this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class) ->disableOriginalConstructor()->getMock(); + $this->promotionService->method('getById')->willReturnCallback(function($id) { + $promotion = new Model\Venta\Promotion(); + $promotion->id = $id; + return $promotion; + }); $this->unitService = $this->getMockBuilder(Service\Venta\Unidad::class) ->disableOriginalConstructor()->getMock(); $this->unitService->method('getById')->willReturnCallback(function($id) { @@ -84,7 +89,7 @@ class ReservationTest extends TestCase $digit = $faker->boolean(100-round(1/11*100)) ? $faker->randomNumber(1) : 'K'; $broker = $faker->boolean(10) ? $faker->randomNumber(8, true) : ''; $promotions = []; - $promotionsCount = $faker->numberBetween(0, 10); + $promotionsCount = $faker->numberBetween(0, 3); for ($i = 0; $i < $promotionsCount; $i++) { $promotions[] = $faker->numberBetween(1, 100); }