feature/cierres #30
@ -9,14 +9,14 @@ class Direcciones extends AbstractSeed
|
|||||||
{
|
{
|
||||||
$comunas = $this->loadValues('comuna', columns: 'id');
|
$comunas = $this->loadValues('comuna', columns: 'id');
|
||||||
|
|
||||||
$n = 50;
|
$n = 100;
|
||||||
$data = [];
|
$data = [];
|
||||||
for ($i = 0; $i < $n; $i++) {
|
for ($i = 0; $i < $n; $i++) {
|
||||||
$row = [
|
$row = [
|
||||||
'calle' => $this->faker->streetName,
|
'calle' => $this->faker->streetName,
|
||||||
'numero' => $this->faker->randomNumber(5),
|
'numero' => $this->faker->randomNumber(5),
|
||||||
'comuna' => $this->faker->randomElement($comunas),
|
'comuna' => $this->faker->randomElement($comunas),
|
||||||
'extra' => '',
|
'extra' => $this->faker->optional(0.9, '')->words(2, true),
|
||||||
];
|
];
|
||||||
$extraRand = ((int) round(rand() / getrandmax())) === 1;
|
$extraRand = ((int) round(rand() / getrandmax())) === 1;
|
||||||
if ($extraRand) {
|
if ($extraRand) {
|
||||||
|
@ -5,9 +5,17 @@ use Tests\Extension\AbstractSeed;
|
|||||||
|
|
||||||
class Inmobiliarias extends AbstractSeed
|
class Inmobiliarias extends AbstractSeed
|
||||||
{
|
{
|
||||||
|
public function getDependencies(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Bancos::class
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$tipos = $this->loadValues('tipo_sociedad', columns: 'id');
|
$tipos = $this->loadValues('tipo_sociedad', columns: 'id');
|
||||||
|
$bancos = $this->loadValues('banco', columns: 'id');
|
||||||
$suffixes = [
|
$suffixes = [
|
||||||
'Inmobiliaria ',
|
'Inmobiliaria ',
|
||||||
'Administradora ',
|
'Administradora ',
|
||||||
@ -28,8 +36,10 @@ class Inmobiliarias extends AbstractSeed
|
|||||||
'dv' => $this->faker->digitoVerificador($rut),
|
'dv' => $this->faker->digitoVerificador($rut),
|
||||||
'razon' => $razon,
|
'razon' => $razon,
|
||||||
'abreviacion' => $abreviacion,
|
'abreviacion' => $abreviacion,
|
||||||
'sigla' => $sigla,
|
'cuenta' => $this->faker->randomNumber(8),
|
||||||
|
'banco' => $this->faker->randomElement($bancos),
|
||||||
'sociedad' => $this->faker->randomElement($tipos),
|
'sociedad' => $this->faker->randomElement($tipos),
|
||||||
|
'sigla' => $sigla,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$this->table('inmobiliaria')
|
$this->table('inmobiliaria')
|
||||||
|
@ -27,9 +27,9 @@ class Proyectos extends AbstractSeed
|
|||||||
'direccion' => $this->faker->randomElement($direcciones),
|
'direccion' => $this->faker->randomElement($direcciones),
|
||||||
'superficie_sobre_nivel' => $this->faker->randomFloat(2, 1000, 10000),
|
'superficie_sobre_nivel' => $this->faker->randomFloat(2, 1000, 10000),
|
||||||
'superficie_bajo_nivel' => $this->faker->randomFloat(2, 0, 5000),
|
'superficie_bajo_nivel' => $this->faker->randomFloat(2, 0, 5000),
|
||||||
'pisos' => $this->faker->randomNumber(2),
|
'pisos' => $this->faker->numberBetween(2, 30),
|
||||||
'subterraneos' => $this->faker->randomNumber(2),
|
'subterraneos' => $this->faker->numberBetween(0, 5),
|
||||||
'corredor' => $this->faker->randomFloat(4, 0, 1)
|
'corredor' => $this->faker->optional(.6, 0)->randomFloat(4, 0, 1)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,91 +26,22 @@ class ReservationTest extends TestCase
|
|||||||
$comunas = $this->container->get(Repository\Comuna::class)->fetchAll();
|
$comunas = $this->container->get(Repository\Comuna::class)->fetchAll();
|
||||||
$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();
|
$brokers = $this->container->get(Repository\Proyecto\Broker::class)->fetchAll();
|
||||||
$projectUnitTypeRepository = $this->container->get(Repository\Proyecto\ProyectoTipoUnidad::class);
|
$units = $this->container->get(Repository\Venta\Unidad::class)->fetchAll();
|
||||||
|
|
||||||
$projectUnitTypes = [];
|
$selectedUnits = [];
|
||||||
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 = [];
|
$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($projectUnitTypes);
|
$selectedUnits[] = $faker->randomElement($units)->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);
|
||||||
}
|
}
|
||||||
|
|
||||||
$brokersCount = $faker->numberBetween(1, 3);
|
$broker = $faker->optional(.1)->randomElement($brokers);
|
||||||
for ($i = 0; $i < $brokersCount; $i++) {
|
|
||||||
$rut = $faker->rut(false, false);
|
|
||||||
$brokerData = [
|
|
||||||
'rut' => $rut,
|
|
||||||
'digit' => $faker->digitoVerificador($rut),
|
|
||||||
'name' => $faker->firstName,
|
|
||||||
'legal_name' => $faker->company,
|
|
||||||
'contact' => $faker->name,
|
|
||||||
'email' => $faker->email,
|
|
||||||
'phone' => $faker->phoneNumber
|
|
||||||
];
|
|
||||||
$broker = $this->container->get(Repository\Proyecto\Broker::class)->create($brokerData);
|
|
||||||
$broker = $this->container->get(Repository\Proyecto\Broker::class)->save($broker);
|
|
||||||
|
|
||||||
$contractData = [
|
$activePromotions = $this->container->get(Repository\Venta\Promotion::class)->fetchActiveByProject($project->id);
|
||||||
'project_id' => $project->id,
|
|
||||||
'broker_rut' => $broker->rut,
|
|
||||||
'commission' => $faker->randomFloat(4, 0, 1),
|
|
||||||
];
|
|
||||||
$contract = $this->container->get(Repository\Proyecto\Broker\Contract::class)->create($contractData);
|
|
||||||
$contract = $this->container->get(Repository\Proyecto\Broker\Contract::class)->save($contract);
|
|
||||||
$state = $this->container->get(Repository\Proyecto\Broker\Contract\State::class)->create([
|
|
||||||
'contract_id' => $contract->id,
|
|
||||||
'type' => Model\Proyecto\Broker\Contract\State\Type::ACTIVE->value,
|
|
||||||
'date' => $faker->dateTimeBetween('-2 months')->format('Y-m-d')
|
|
||||||
]);
|
|
||||||
$this->container->get(Repository\Proyecto\Broker\Contract\State::class)->save($state);
|
|
||||||
}
|
|
||||||
$contracts = $this->container->get(Repository\Proyecto\Broker\Contract::class)->fetchActiveByProject($project->id);
|
|
||||||
$broker = $faker->boolean(10) ? $faker->randomElement($contracts)->broker : null;
|
|
||||||
|
|
||||||
$promotionTypes = Model\Venta\Promotion\Type::cases();
|
$promotionsCount = $faker->numberBetween(0, min(3, count($activePromotions)));
|
||||||
$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 = [];
|
$promotions = [];
|
||||||
for ($i = 0; $i < $promotionsCount; $i++) {
|
for ($i = 0; $i < $promotionsCount; $i++) {
|
||||||
$promotions[] = $faker->randomElement($activePromotions)->id;
|
$promotions[] = $faker->randomElement($activePromotions)->id;
|
||||||
@ -125,12 +56,12 @@ class ReservationTest extends TestCase
|
|||||||
'buyer_last_name' => $faker->lastName,
|
'buyer_last_name' => $faker->lastName,
|
||||||
'buyer_last_name2' => $faker->lastName,
|
'buyer_last_name2' => $faker->lastName,
|
||||||
'buyer_email' => $faker->email,
|
'buyer_email' => $faker->email,
|
||||||
'buyer_phone' => $faker->phoneNumber,
|
'buyer_phone' => $faker->randomNumber(8),
|
||||||
'buyer_address_street' => $faker->streetName,
|
'buyer_address_street' => $faker->streetName,
|
||||||
'buyer_address_number' => $faker->buildingNumber,
|
'buyer_address_number' => $faker->buildingNumber,
|
||||||
'buyer_address_extra' => $faker->streetAddress,
|
'buyer_address_extra' => $faker->streetAddress,
|
||||||
'buyer_address_comuna_id' => $faker->randomElement($comunas)->id,
|
'buyer_address_comuna_id' => $faker->randomElement($comunas)->id,
|
||||||
'units' => $units,
|
'units' => $selectedUnits,
|
||||||
'units_value' => $unitsValue,
|
'units_value' => $unitsValue,
|
||||||
'broker_rut' => $broker ? $broker->rut : '',
|
'broker_rut' => $broker ? $broker->rut : '',
|
||||||
];
|
];
|
||||||
@ -145,14 +76,16 @@ class ReservationTest extends TestCase
|
|||||||
$this->assertEquals($data['buyer_rut'], $reservation->buyer->rut);
|
$this->assertEquals($data['buyer_rut'], $reservation->buyer->rut);
|
||||||
$this->assertEquals($data['buyer_digit'], $reservation->buyer->digito);
|
$this->assertEquals($data['buyer_digit'], $reservation->buyer->digito);
|
||||||
$this->assertEquals($data['buyer_names'], $reservation->buyer->nombres);
|
$this->assertEquals($data['buyer_names'], $reservation->buyer->nombres);
|
||||||
$this->assertEquals($data['buyer_last_name'], $reservation->buyer->apellido_paterno);
|
$this->assertEquals($data['buyer_last_name'], $reservation->buyer->apellidoPaterno);
|
||||||
$this->assertEquals($data['buyer_last_name2'], $reservation->buyer->apellido_materno);
|
$this->assertEquals($data['buyer_last_name2'], $reservation->buyer->apellidoMaterno);
|
||||||
$this->assertEquals($data['buyer_email'], $reservation->buyer->datos->email);
|
$this->assertEquals($data['buyer_email'], $reservation->buyer->datos->email);
|
||||||
$this->assertEquals($data['buyer_phone'], $reservation->buyer->datos->telefono);
|
$this->assertEquals($data['buyer_phone'], $reservation->buyer->datos->telefono);
|
||||||
$this->assertEquals($data['buyer_address_street'], $reservation->buyer->direccion->calle);
|
$this->assertEquals($data['buyer_address_street'], $reservation->buyer->datos->direccion->calle);
|
||||||
$this->assertEquals($data['buyer_address_number'], $reservation->buyer->direccion->numero);
|
$this->assertEquals($data['buyer_address_number'], $reservation->buyer->datos->direccion->numero);
|
||||||
$this->assertEquals($data['buyer_address_extra'], $reservation->buyer->direccion->extra);
|
$this->assertEquals($data['buyer_address_extra'], $reservation->buyer->datos->direccion->extra);
|
||||||
$this->assertEquals($data['buyer_address_comuna_id'], $reservation->buyer->direccion->comuna->id);
|
$this->assertEquals($data['buyer_address_comuna_id'], $reservation->buyer->datos->direccion->comuna->id);
|
||||||
$this->assertEquals($data['broker_rut'], $reservation->broker->rut);
|
if ($broker !== null) {
|
||||||
|
$this->assertEquals($data['broker_rut'], $reservation->broker->rut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,22 @@ namespace Tests\Unit\Service;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
use Faker\Factory;
|
||||||
use Incoviba\Service\Valor;
|
use Incoviba\Service\Valor;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
|
||||||
class ValorTest extends TestCase
|
class ValorTest extends TestCase
|
||||||
{
|
{
|
||||||
protected Service\UF $ufService;
|
protected Service\UF $ufService;
|
||||||
|
protected static float $staticUF = 35498.76;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->ufService = $this->getMockBuilder(Service\UF::class)
|
$this->ufService = $this->getMockBuilder(Service\UF::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$this->ufService->method('get')->willReturn(35000.0);
|
$faker = Factory::create();
|
||||||
|
$this->ufService->method('get')->willReturn(self::$staticUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cleanDataProvider(): array
|
public static function cleanDataProvider(): array
|
||||||
@ -55,14 +59,14 @@ class ValorTest extends TestCase
|
|||||||
$result = $valorService->toUF($input, $date);
|
$result = $valorService->toUF($input, $date);
|
||||||
|
|
||||||
$this->assertIsFloat($result);
|
$this->assertIsFloat($result);
|
||||||
$this->assertEquals($input / 35000, $result);
|
$this->assertEquals($input / self::$staticUF, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function pesosDataProvider(): array
|
public static function pesosDataProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[1000.01, 1000.01*35000, false],
|
[1000.01, round(1000.01*self::$staticUF), false],
|
||||||
[1000, 1000*35000, true],
|
[1000, round(1000*self::$staticUF), true],
|
||||||
['1000', 1000, false],
|
['1000', 1000, false],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,11 @@ class ReservationTest extends TestCase
|
|||||||
$persona->rut = $data['rut'];
|
$persona->rut = $data['rut'];
|
||||||
return $persona;
|
return $persona;
|
||||||
});
|
});
|
||||||
|
$this->personaService->method('getById')->willReturnCallback(function($id) {
|
||||||
|
$persona = new Model\Persona();
|
||||||
|
$persona->rut = $id;
|
||||||
|
return $persona;
|
||||||
|
});
|
||||||
$this->brokerService = $this->getMockBuilder(Service\Proyecto\Broker::class)
|
$this->brokerService = $this->getMockBuilder(Service\Proyecto\Broker::class)
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class)
|
$this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class)
|
||||||
@ -83,7 +88,7 @@ class ReservationTest extends TestCase
|
|||||||
$unitsValue = [];
|
$unitsValue = [];
|
||||||
$unitsCount = $faker->numberBetween(1, 10);
|
$unitsCount = $faker->numberBetween(1, 10);
|
||||||
for ($i = 0; $i < $unitsCount; $i++) {
|
for ($i = 0; $i < $unitsCount; $i++) {
|
||||||
$units[] = $faker->numberBetween(1, 100);
|
$units[] = $faker->unique()->numberBetween(1, 100);
|
||||||
$unitsValue[] = $faker->randomFloat(2, 1000, 10000);
|
$unitsValue[] = $faker->randomFloat(2, 1000, 10000);
|
||||||
}
|
}
|
||||||
$digit = $faker->boolean(100-round(1/11*100)) ? $faker->randomNumber(1) : 'K';
|
$digit = $faker->boolean(100-round(1/11*100)) ? $faker->randomNumber(1) : 'K';
|
||||||
|
Reference in New Issue
Block a user