Files
Investidor-V2/tests/Feature/IvaRegularizationDraftTest.php

38 lines
3.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 IvaRegularizationDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_frozen_d_adjustments_assets_totals_and_history_recover_without_changing_other_books(): 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-e-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);
$e=$s['regularizations']['opportunity:370'];
$this->assertCount(2,$e['events']);$this->assertCount(1,$e['history']);
$this->assertSame(['numerator'=>'132','denominator'=>'25'],$e['result']['events'][0]['delta']);
$this->assertSame(['numerator'=>'4','denominator'=>'3'],$s['books']['opportunity:370']['result']['periods'][0]['exactFields']['13']);
foreach(['12'=>'5.28','13'=>'1.333333','15'=>'29.44','16'=>'161.333333','17'=>'131.893333','18'=>'0.00'] as $field=>$value)$this->assertSame($value,$s['books']['opportunity:370']['result']['periods'][0]['fields'][(string)$field]);
$frozen=json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l2e-preserved.json')),true,flags:JSON_THROW_ON_ERROR);
$prior=json_decode($frozen['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
$this->assertSame($prior['books']['opportunity:370']['result'],$s['books']['opportunity:370']['history'][array_key_last($s['books']['opportunity:370']['history'])]);
$this->assertSame($prior['books']['opportunity:370']['result'],$e['events'][0]['source']);
foreach($prior as $key=>$map){if($key==='version')continue;foreach($map as $context=>$original){if($key==='books'&&$context==='opportunity:370')continue;$this->assertSame($original,$s[$key][$context]);}}
$this->assertSame('08',$s['books']['opportunity:372']['rows'][0]['field']);
$this->assertSame(['numerator'=>'16','denominator'=>'3'],$s['books']['opportunity:372']['result']['rows'][0]['deductibleExact']);
file_put_contents(base_path('outputs/iva-l2-e-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
}
}