fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+57 -13
View File
@@ -1,23 +1,67 @@
<?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 IrpcGroupedDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_grouped_irpc_rates_and_existing_fx_recover_with_originals_and_accepted_history():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()]));
$d=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-grouped-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');$recovered=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');$this->assertSame($d['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);$s=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcWithholdings'][$d['context_opportunity']];
$foreign=$b['result']['rows'][2];$this->assertSame('calculated',$foreign['status']);$this->assertSame(20,$foreign['rate']);$this->assertSame(['numerator'=>'64000','denominator'=>'1'],$foreign['base']);$this->assertSame(['numerator'=>'12800','denominator'=>'1'],$foreign['tax']);$this->assertSame(['numerator'=>'7800','denominator'=>'1'],$foreign['outstanding']);$this->assertSame('1000',$foreign['conversion']['originalAmount']);$this->assertSame('USD',$foreign['conversion']['originalCurrency']);$this->assertSame('2026-10-20',$foreign['conversion']['date']);$this->assertSame('2026-10-02',$foreign['eventDate']);
$this->assertSame(10,$b['result']['rows'][3]['rate']);$this->assertSame('on_account',$b['result']['rows'][4]['nature']);$this->assertSame(['numerator'=>'10000','denominator'=>'1'],$b['result']['rows'][4]['tax']);$this->assertSame(['numerator'=>'640','denominator'=>'1'],$b['result']['rows'][5]['settled']);$this->assertSame(['numerator'=>'640','denominator'=>'1'],$b['result']['rows'][5]['outstanding']);$this->assertSame('10',$b['result']['paymentConversions']['p4']['originalAmount']);$this->assertSame('USD',$b['result']['payments'][3]['currency']);
$old=json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-l5-preserved.json')),true,flags:JSON_THROW_ON_ERROR);$prior=json_decode($old['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);foreach($prior as$k=>$v){if(in_array($k,['irpcWithholdings','currencyEvents'],true))continue;$this->assertSame($v,$s[$k],$k);}
$oldBook=$prior['irpcWithholdings'][$d['context_opportunity']];$this->assertSame($oldBook['result'],$b['history'][array_key_last($b['history'])]);$this->assertSame($oldBook['rows'],array_slice($b['rows'],0,count($oldBook['rows'])));$this->assertSame($oldBook['payments'],array_slice($b['payments'],0,count($oldBook['payments'])));foreach(($prior['currencyEvents']??[])as$ctx=>$value){if($ctx!==$d['context_opportunity'])$this->assertSame($value,$s['currencyEvents'][$ctx]);}
if(is_dir(base_path('outputs/irpc-l5-grouped-20261025')))file_put_contents(base_path('outputs/irpc-l5-grouped-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
}
use DatabaseTransactions;
public function test_grouped_irpc_rates_and_existing_fx_recover_with_originals_and_accepted_history(): 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()]));
$d = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-grouped-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
$personal = ['person_type' => $d['person_type']];
unset($d['person_type']);
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
$this->assertSame($d['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$b = $s['irpcWithholdings'][$d['context_opportunity']];
$foreign = $b['result']['rows'][2];
$this->assertSame('calculated', $foreign['status']);
$this->assertSame(20, $foreign['rate']);
$this->assertSame(['numerator' => '64000', 'denominator' => '1'], $foreign['base']);
$this->assertSame(['numerator' => '12800', 'denominator' => '1'], $foreign['tax']);
$this->assertSame(['numerator' => '7800', 'denominator' => '1'], $foreign['outstanding']);
$this->assertSame('1000', $foreign['conversion']['originalAmount']);
$this->assertSame('USD', $foreign['conversion']['originalCurrency']);
$this->assertSame('2026-10-20', $foreign['conversion']['date']);
$this->assertSame('2026-10-02', $foreign['eventDate']);
$this->assertSame(10, $b['result']['rows'][3]['rate']);
$this->assertSame('on_account', $b['result']['rows'][4]['nature']);
$this->assertSame(['numerator' => '10000', 'denominator' => '1'], $b['result']['rows'][4]['tax']);
$this->assertSame(['numerator' => '640', 'denominator' => '1'], $b['result']['rows'][5]['settled']);
$this->assertSame(['numerator' => '640', 'denominator' => '1'], $b['result']['rows'][5]['outstanding']);
$this->assertSame('10', $b['result']['paymentConversions']['p4']['originalAmount']);
$this->assertSame('USD', $b['result']['payments'][3]['currency']);
$old = json_decode(file_get_contents(base_path('tests/frontend/fixtures/irpc-l5-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
$prior = json_decode($old['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
foreach ($prior as $k => $v) {
if (in_array($k, ['irpcWithholdings', 'currencyEvents'], true)) {
continue;
}$this->assertSame($v, $s[$k], $k);
}
$oldBook = $prior['irpcWithholdings'][$d['context_opportunity']];
$this->assertSame($oldBook['result'], $b['history'][array_key_last($b['history'])]);
$this->assertSame($oldBook['rows'], array_slice($b['rows'], 0, count($oldBook['rows'])));
$this->assertSame($oldBook['payments'], array_slice($b['payments'], 0, count($oldBook['payments'])));
foreach (($prior['currencyEvents'] ?? []) as $ctx => $value) {
if ($ctx !== $d['context_opportunity']) {
$this->assertSame($value, $s['currencyEvents'][$ctx]);
}
}
if (is_dir(base_path('outputs/irpc-l5-grouped-20261025'))) {
file_put_contents(base_path('outputs/irpc-l5-grouped-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}