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
+47 -20
View File
@@ -1,34 +1,61 @@
<?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 IvaBeveragePartitionDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_partition_recovery_preserves_prior_effective_deduction_without_reusing_it_for_restitution(): 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-e-partitions-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);$book=$s['ivaBeverageRestitutions']['opportunity:375'];
$this->assertSame(['numerator'=>'10','denominator'=>'1'],$book['result']['rows'][0]['requested']);
$this->assertSame('determined',$book['result']['rows'][0]['status']);
$this->assertNull($book['result']['rows'][0]['approved']);$this->assertNull($book['result']['rows'][0]['received']);
$allocation=$book['result']['inputs'][0]['allocation'];
foreach(['from'=>'6','to'=>'16','deductionFrom'=>'0','deductionTo'=>'6']as$key=>$value)$this->assertSame($value,$allocation[$key]);
$this->assertNotEmpty($allocation['reference']);$this->assertNotEmpty($allocation['deductionReference']);
$originalDeductions=[];foreach($s['books']['opportunity:375']['history']as$calc)foreach($calc['rows']as$row)if($row['id']==='beverage-purchase')$originalDeductions[]=$row['deductibleExact']??null;
$this->assertContains(['numerator'=>'6','denominator'=>'1'],$originalDeductions);
foreach(['iva-l3e-preserved','iva-l3ab-preserved']as$fixture){$accepted=json_decode(file_get_contents(base_path('tests/frontend/fixtures/'.$fixture.'.json')),true,flags:JSON_THROW_ON_ERROR);foreach(json_decode($accepted['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]);}}
$this->assertSame(['numerator'=>'72','denominator'=>'1'],$s['ivaClosures']['opportunity:373']['result']['rows'][2]['fields']['24']);
$this->assertSame(['numerator'=>'450000','denominator'=>'1'],$s['ivaRefunds']['opportunity:374']['result']['rows'][0]['received']);
file_put_contents(base_path('outputs/iva-l3-e-partitions-20261025/recovered.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
$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-e-partitions-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);
$book = $s['ivaBeverageRestitutions']['opportunity:375'];
$this->assertSame(['numerator' => '10', 'denominator' => '1'], $book['result']['rows'][0]['requested']);
$this->assertSame('determined', $book['result']['rows'][0]['status']);
$this->assertNull($book['result']['rows'][0]['approved']);
$this->assertNull($book['result']['rows'][0]['received']);
$allocation = $book['result']['inputs'][0]['allocation'];
foreach (['from' => '6', 'to' => '16', 'deductionFrom' => '0', 'deductionTo' => '6'] as $key => $value) {
$this->assertSame($value, $allocation[$key]);
}
$this->assertNotEmpty($allocation['reference']);
$this->assertNotEmpty($allocation['deductionReference']);
$originalDeductions = [];
foreach ($s['books']['opportunity:375']['history'] as $calc) {
foreach ($calc['rows'] as $row) {
if ($row['id'] === 'beverage-purchase') {
$originalDeductions[] = $row['deductibleExact'] ?? null;
}
}
}
$this->assertContains(['numerator' => '6', 'denominator' => '1'], $originalDeductions);
foreach (['iva-l3e-preserved', 'iva-l3ab-preserved'] as $fixture) {
$accepted = json_decode(file_get_contents(base_path('tests/frontend/fixtures/'.$fixture.'.json')), true, flags: JSON_THROW_ON_ERROR);
foreach (json_decode($accepted['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]);
}
}
}
$this->assertSame(['numerator' => '72', 'denominator' => '1'], $s['ivaClosures']['opportunity:373']['result']['rows'][2]['fields']['24']);
$this->assertSame(['numerator' => '450000', 'denominator' => '1'], $s['ivaRefunds']['opportunity:374']['result']['rows'][0]['received']);
file_put_contents(base_path('outputs/iva-l3-e-partitions-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}