Files

70 lines
4.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Tests\TestCase;
final class IvaRefundDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_refund_recovers_allocation_request_decision_receipts_history_and_all_prior_maps(): void
{
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
$this->assertSame(55441, (int) $target->port);
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
$draft = json_decode(file_get_contents(base_path('outputs/iva-l3-d-20261025/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$b = $s['ivaRefunds']['opportunity:374'];
$this->assertCount(1, $b['rows']);
$this->assertCount(1, $b['history']);
$r = $b['result']['rows'][0];
$this->assertSame('determined', $r['status']);
$this->assertSame('compatible', $r['eligibility']);
foreach (['requested' => '600000', 'reported' => '200000', 'approved' => '550000', 'received' => '450000', 'awaitingReceipt' => '100000', 'notGranted' => '50000'] as $f => $v) {
$this->assertSame(['numerator' => $v, 'denominator' => '1'], $r[$f]);
}
$input = $b['result']['inputs'][0];
$this->assertSame('SYNTHETIC QA pedidoR1', $input['requestReference']);
$this->assertSame('2026-02-15', $input['requestDate']);
$this->assertSame('partial', $input['decision']);
$this->assertSame('SYNTHETIC QA decisãoD1', $input['decisionReference']);
$this->assertCount(2, $input['receipts']);
$allocation = $s['ivaClosures']['opportunity:374']['result']['rows'][0];
foreach (['25' => '800000', '26' => '200000', '27' => '600000'] as $f => $v) {
$this->assertSame(['numerator' => $v, 'denominator' => '1'], $allocation['fields'][(string) $f]);
}
$accepted = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3d-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
$accepted = json_decode($accepted['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
foreach ($accepted as $key => $map) {
if ($key === 'version') {
continue;
}foreach ($map as $context => $original) {
$this->assertSame($original, $s[$key][$context]);
}
}
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3ab-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
if ($key === 'version') {
continue;
}foreach ($map as $context => $original) {
$this->assertSame($original, $s[$key][$context]);
}
}
$old = $s['ivaClosures']['opportunity:373']['result']['rows'][2];
$this->assertSame(['numerator' => '72', 'denominator' => '1'], $old['fields']['24']);
$this->assertSame(['numerator' => '30', 'denominator' => '1'], $old['paid']);
$this->assertSame(['numerator' => '42', 'denominator' => '1'], $old['outstanding']);
file_put_contents(base_path('outputs/iva-l3-d-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}