feature/cierres (#30)
Reservas agregar y aprobar Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #30
This commit is contained in:
92
app/tests/integration/API/Ventas/ReservationTest.php
Normal file
92
app/tests/integration/API/Ventas/ReservationTest.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace Incoviba\Tests\Integration\API\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Tests\Extension\AbstractIntegration;
|
||||
use Tests\Extension\ContainerTrait;
|
||||
use Tests\Extension\Faker\Provider\Rut;
|
||||
|
||||
class ReservationTest extends TestCase
|
||||
{
|
||||
use ContainerTrait;
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$faker = Faker\Factory::create('es_CL');
|
||||
$faker->addProvider(new Rut($faker));
|
||||
|
||||
$comunas = $this->container->get(Repository\Comuna::class)->fetchAll();
|
||||
$projects = $this->container->get(Repository\Proyecto::class)->fetchAll();
|
||||
$project = $faker->randomElement($projects);
|
||||
$brokers = $this->container->get(Repository\Proyecto\Broker::class)->fetchAll();
|
||||
$units = $this->container->get(Repository\Venta\Unidad::class)->fetchAll();
|
||||
|
||||
$selectedUnits = [];
|
||||
$unitsValue = [];
|
||||
$unitsCount = $faker->numberBetween(1, 3);
|
||||
for ($i = 0; $i < $unitsCount; $i++) {
|
||||
$selectedUnits[] = $faker->randomElement($units)->id;
|
||||
$unitsValue[] = $faker->randomFloat(2, 1000, 10000);
|
||||
}
|
||||
|
||||
$broker = $faker->randomElement($brokers);
|
||||
|
||||
$activePromotions = $this->container->get(Repository\Venta\Promotion::class)->fetchActiveByProject($project->id);
|
||||
|
||||
$promotionsCount = $faker->numberBetween(0, min(3, count($activePromotions)));
|
||||
$promotions = [];
|
||||
for ($i = 0; $i < $promotionsCount; $i++) {
|
||||
$promotions[] = $faker->randomElement($activePromotions)->id;
|
||||
}
|
||||
$rut = $faker->rut(false, false);
|
||||
$data = [
|
||||
'project_id' => $faker->randomElement($projects)->id,
|
||||
'date' => $faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'),
|
||||
'buyer_rut' => $rut,
|
||||
'buyer_digit' => $faker->digitoVerificador($rut),
|
||||
'buyer_names' => $faker->firstName,
|
||||
'buyer_last_name' => $faker->lastName,
|
||||
'buyer_last_name2' => $faker->lastName,
|
||||
'buyer_email' => $faker->email,
|
||||
'buyer_phone' => $faker->randomNumber(8),
|
||||
'buyer_address_street' => $faker->streetName,
|
||||
'buyer_address_number' => $faker->buildingNumber,
|
||||
'buyer_address_extra' => $faker->streetAddress,
|
||||
'buyer_address_comuna_id' => $faker->randomElement($comunas)->id,
|
||||
'units' => $selectedUnits,
|
||||
'units_value' => $unitsValue,
|
||||
'broker_rut' => $broker ? $broker->rut : '',
|
||||
];
|
||||
if (count($promotions) > 0) {
|
||||
$data['promotions'] = $promotions;
|
||||
}
|
||||
|
||||
$reservation = $this->container->get(Service\Venta\Reservation::class)->add($data);
|
||||
$this->assertInstanceOf(Model\Venta\Reservation::class, $reservation);
|
||||
$this->assertEquals($data['date'], $reservation->date->format('Y-m-d'));
|
||||
$this->assertEquals($data['project_id'], $reservation->project->id);
|
||||
$this->assertEquals($data['buyer_rut'], $reservation->buyer->rut);
|
||||
$this->assertEquals($data['buyer_digit'], $reservation->buyer->digito);
|
||||
$this->assertEquals($data['buyer_names'], $reservation->buyer->nombres);
|
||||
$this->assertEquals($data['buyer_last_name'], $reservation->buyer->apellidoPaterno);
|
||||
$this->assertEquals($data['buyer_last_name2'], $reservation->buyer->apellidoMaterno);
|
||||
$this->assertEquals($data['buyer_email'], $reservation->buyer->datos->email);
|
||||
$this->assertEquals($data['buyer_phone'], $reservation->buyer->datos->telefono);
|
||||
$this->assertEquals($data['buyer_address_street'], $reservation->buyer->datos->direccion->calle);
|
||||
$this->assertEquals($data['buyer_address_number'], $reservation->buyer->datos->direccion->numero);
|
||||
$this->assertEquals($data['buyer_address_extra'], $reservation->buyer->datos->direccion->extra);
|
||||
$this->assertEquals($data['buyer_address_comuna_id'], $reservation->buyer->datos->direccion->comuna->id);
|
||||
if ($broker !== null) {
|
||||
$this->assertEquals($data['broker_rut'], $reservation->broker->rut);
|
||||
}
|
||||
$this->assertEquals(1, $reservation->currentState()->type->value);
|
||||
}
|
||||
}
|
@ -11,17 +11,12 @@ use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Tests\Extension\ContainerTrait;
|
||||
use Tests\Extension\Faker\Provider\Rut;
|
||||
|
||||
class QueueTest extends TestCase
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
require_once implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), 'setup', 'container.php']);
|
||||
$this->container = buildContainer();
|
||||
}
|
||||
use ContainerTrait;
|
||||
|
||||
public function testServiceWorker(): void
|
||||
{
|
||||
|
Reference in New Issue
Block a user