Pruebas de Toku

This commit is contained in:
Juan Pablo Vial
2025-05-09 18:04:57 -04:00
parent c2f98c8b0d
commit db84187461
8 changed files with 274 additions and 24 deletions

View File

@ -18,8 +18,11 @@ class InvoiceTest extends TestCase
protected Model\MediosPago\Toku\Invoice $invoice;
protected Repository\MediosPago\Toku\Invoice $invoiceRepository;
protected Model\Venta\Cuota $cuota;
protected Service\Venta\Pago $pagoService;
protected Service\UF $ufService;
protected array $getData;
protected array $saveData;
protected \DateTimeInterface $fechaUF2;
protected function setUp(): void
{
@ -45,11 +48,27 @@ class InvoiceTest extends TestCase
$subscription->venta = $venta;
$subscription->toku_id = $faker->ean13();
$fechaUF1 = $faker->dateTimeInInterval('-3 years', '-1 weeks');
$this->fechaUF2 = $faker->dateTimeInInterval('-1 month', 'now');
$uf1 = $faker->randomFloat(2, 30000, 40000);
$uf2 = $faker->randomFloat(2, 30000, 40000);
$this->ufService = $this->getMockBuilder(Service\UF::class)
->disableOriginalConstructor()->getMock();
$this->ufService->method('get')->willReturnCallback(function(\DateTimeInterface $dateTime) use ($fechaUF1, $uf1, $uf2, $faker) {
return match ($dateTime->format('Y-m-d H:i:s')) {
$fechaUF1->format('Y-m-d H:i:s') => $uf1,
$this->fechaUF2->format('Y-m-d H:i:s') => $uf2,
default => $faker->randomFloat(2, 30000, 40000)
};
});
$pago = $this->getMockBuilder(Model\Venta\Pago::class)
->disableOriginalConstructor()->getMock();
$pago->fecha = $faker->dateTime();
$pago->fecha = $fechaUF1;
$pago->valor = $faker->randomNumber(6, true);
$pago->method('valor')->willReturn($faker->randomFloat(3, true));
$pago->uf = $uf1;
$pago->method('valor')->willReturn($pago->valor / $uf1);
$this->cuota = $this->getMockBuilder(Model\Venta\Cuota::class)
->disableOriginalConstructor()->getMock();
$this->cuota->id = $faker->randomNumber();
@ -71,6 +90,7 @@ class InvoiceTest extends TestCase
->disableOriginalConstructor()->getMock();
$this->invoiceRepository->method('fetchById')->willReturn($this->invoice);
$this->invoiceRepository->method('fetchByCuota')->willReturn($this->invoice);
$this->invoiceRepository->method('fetchByTokuId')->willReturn($this->invoice);
$this->getData = [
'customer' => $customer->toku_id,
@ -151,22 +171,33 @@ class InvoiceTest extends TestCase
$this->client->method('post')->willReturn($postResponse);
$this->client->method('put')->willReturn($postResponse);
$this->client->method('delete')->willReturn($deleteResponse);
$this->pagoService = $this->getMockBuilder(Service\Venta\Pago::class)
->disableOriginalConstructor()->getMock();
$this->pagoService->method('depositar')->willReturn(true);
}
public function testGetById(): void
{
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
$this->assertEquals(json_decode(json_encode($this->invoice), true), $service->getById($this->invoice->toku_id));
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
$this->assertEquals(json_decode(json_encode($this->invoice), true), $service->getById($this->cuota->id));
}
public function testGetByExternalId(): void
{
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
$this->assertEquals(json_decode(json_encode($this->invoice), true), $service->getByExternalId($this->invoice->toku_id));
}
public function testGet(): void
{
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
$this->assertEquals($this->getData, $service->get($this->invoice->toku_id));
}
public function testAdd(): void
{
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
$sendData = [
'customer' => $this->postData['customer'],
@ -179,7 +210,7 @@ class InvoiceTest extends TestCase
}
public function testEdit(): void
{
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
$sendData = [
'customer' => $this->postData['customer'],
@ -192,9 +223,43 @@ class InvoiceTest extends TestCase
}
public function testDelete(): void
{
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
$this->expectNotToPerformAssertions();
$service->delete($this->invoice->toku_id);
}
public function testUpdate(): void
{
$faker = Faker\Factory::create();
$uf2 = $this->ufService->get($this->fechaUF2);
$valor = round($this->cuota->pago->valor() * $uf2);
$request = [
'id' => $faker->ean13(),
'event_type' => 'payment_intent.succeeded',
'payment_intent' => [
'id' => $faker->ean13(),
'invoice' => $this->invoice->toku_id,
'customer' => $this->getData['customer'],
'id_account' => $faker->ean13(),
'gateway' => 'khipu_transfer',
'amount' => $valor,
'status' => 'AUTHORIZED',
'payment_method' => $faker->ean13(),
'transaction_date' => $this->fechaUF2->format('Y-m-d H:i:s.u'),
'card_detail' => null,
'buy_order' => $faker->ean8(),
'child_buy_order' => null,
'authorization_code' => null,
'payment_type_code' => null,
'response_code' => null,
'toku_response_code' => null,
'installments_number' => null,
'mc_order_id' => null,
]
];
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
$this->assertTrue($service->update($request['payment_intent']['invoice'], $request['payment_intent']));
}
}