Pruebas y chequeos

This commit is contained in:
Juan Pablo Vial
2025-08-29 18:33:30 -04:00
parent eeee12e6e9
commit c220e7438b
5 changed files with 57 additions and 6 deletions

View File

@ -82,7 +82,9 @@ class Reservation extends Common\Ideal\Repository
$model = parent::load($data_row); $model = parent::load($data_row);
$this->fetchUnits($model, $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); $this->fetchPromotions($model, $data_row);
return $model; return $model;
} }

View File

@ -7,7 +7,8 @@ use Incoviba\Repository;
class State extends Common\Ideal\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); parent::__construct($connection);
} }

View File

@ -190,6 +190,7 @@ class Reservation extends Ideal\Service\API
} }
protected function addUnits(Model\Venta\Reservation $reservation, array $units): void protected function addUnits(Model\Venta\Reservation $reservation, array $units): void
{ {
//var_dump(__LINE__, $units);
foreach ($units as $unit_id => $value) { foreach ($units as $unit_id => $value) {
try { try {
$unit = $this->unitService->getById($unit_id); $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 protected function addPromotions(Model\Venta\Reservation $reservation, array $promotions): void
{ {
var_dump(__LINE__, $promotions);
foreach ($promotions as $promotion_id) { foreach ($promotions as $promotion_id) {
try { try {
$promotion = $this->promotionService->getById($promotion_id); $promotion = $this->promotionService->getById($promotion_id);

View File

@ -27,13 +27,37 @@ class ReservationTest extends TestCase
$projects = $this->container->get(Repository\Proyecto::class)->fetchAll(); $projects = $this->container->get(Repository\Proyecto::class)->fetchAll();
$project = $faker->randomElement($projects); $project = $faker->randomElement($projects);
$unitTypes = $this->container->get(Repository\Proyecto\TipoUnidad::class)->fetchAll(); $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); $unitsRepository = $this->container->get(Repository\Venta\Unidad::class);
$units = []; $units = [];
$unitsValue = []; $unitsValue = [];
$unitsCount = $faker->numberBetween(1, 3); $unitsCount = $faker->numberBetween(1, 3);
for ($i = 0; $i < $unitsCount; $i++) { for ($i = 0; $i < $unitsCount; $i++) {
$type = $faker->randomElement($unitTypes); $type = $faker->randomElement($projectUnitTypes);
$units[] = $unitsRepository->fetchByProyectoAndTipo($project->id, $type->id); $unitData = [
'pt' => $type->id,
];
$unit = $unitsRepository->create($unitData);
$unit = $unitsRepository->save($unit);
$units[] = $unit->id;
$unitsValue[] = $faker->randomFloat(2, 1000, 10000); $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); $contracts = $this->container->get(Repository\Proyecto\Broker\Contract::class)->fetchActiveByProject($project->id);
$broker = $faker->boolean(10) ? $faker->randomElement($contracts)->broker : null; $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); $promotionsCount = $faker->numberBetween(0, 3);
$promotions = []; $promotions = [];
for ($i = 0; $i < $promotionsCount; $i++) { for ($i = 0; $i < $promotionsCount; $i++) {

View File

@ -58,6 +58,11 @@ class ReservationTest extends TestCase
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class) $this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class)
->disableOriginalConstructor()->getMock(); ->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) $this->unitService = $this->getMockBuilder(Service\Venta\Unidad::class)
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->unitService->method('getById')->willReturnCallback(function($id) { $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'; $digit = $faker->boolean(100-round(1/11*100)) ? $faker->randomNumber(1) : 'K';
$broker = $faker->boolean(10) ? $faker->randomNumber(8, true) : ''; $broker = $faker->boolean(10) ? $faker->randomNumber(8, true) : '';
$promotions = []; $promotions = [];
$promotionsCount = $faker->numberBetween(0, 10); $promotionsCount = $faker->numberBetween(0, 3);
for ($i = 0; $i < $promotionsCount; $i++) { for ($i = 0; $i < $promotionsCount; $i++) {
$promotions[] = $faker->numberBetween(1, 100); $promotions[] = $faker->numberBetween(1, 100);
} }