Files
Investidor-V2/tests/Feature/IvaAcquisitionAllocationDraftTest.php
T

49 lines
3.3 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 IvaAcquisitionAllocationDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_allocation_recovers_with_exact_fractions_and_preserved_ABC(): 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-l2-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']);
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$book = $store['books']['opportunity:370'];
$this->assertCount(4, $book['rows']);
$this->assertSame(['eligible','eligible','eligible','eligible'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
$this->assertSame('24.16', $book['result']['periods'][0]['fields']['15']);
$this->assertCount(1, $book['history']);
$this->assertSame('10.72', $book['result']['periods'][0]['fields']['11']);
$this->assertSame('135.84', $book['result']['periods'][0]['fields']['17']);
$this->assertSame('customs', $book['rows'][3]['documentType']);
$this->assertSame('actual', $book['rows'][0]['d']['method']);
$this->assertSame(['numerator'=>'16','denominator'=>'3'], $book['result']['rows'][0]['deductibleExact']);
$this->assertSame(['numerator'=>'17','denominator'=>'50'], $book['result']['rows'][1]['allocationCalculation']['ratio']);
$this->assertSame('yes', $book['rows'][0]['d']['facts']['communication']);
$this->assertSame('6.40', $store['books']['opportunity:371']['result']['periods'][0]['fields']['15']);
$this->assertNull($store['books']['opportunity:371']['result']['periods'][0]['fields']['16']);
$this->assertSame('public_works', $store['books']['opportunity:371']['rows'][0]['d']['reducedId']);
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l2d-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, $store[$key][$context]);
}
file_put_contents(base_path('outputs/iva-l2-d-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}