Files
Investidor-V2/tests/Feature/IrpcNormalDepreciationDraftTest.php
T
2026-10-26 09:24:06 +02:00

27 lines
3.2 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 IrpcNormalDepreciationDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_depreciation_parameters_quotas_prior_balances_and_results_recover_without_rewriting_legacy_assets():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()]));$id=null;$etag=null;
$expected=['months'=>['6780','4480','7168'],'declining'=>['6630','4330','6928'],'prior'=>['6730','4430','7088'],'specific'=>['13535','8935','7148']];
foreach(['months','declining','prior','specific','missing']as$case){
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-depreciation/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);$p=['person_type'=>$d['person_type']];unset($d['person_type']);
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$p,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');else$this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$p,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$this->assertSame('IRPC-normal-adjustments/7',$m['version']);$this->assertSame($b['depreciation'],$m['depreciation']['input']);$this->assertSame($b['schedules']['assets'],$m['schedules']['input']['assets']);$this->assertSame([],$m['schedules']['assets']);$this->assertContains('IRPC-normal-adjustments/6',array_column(array_column($b['history'],'model'),'version'));$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertNull($m['tax']);$this->assertNull($m['assessment']['finalBalance']['payable']);
if($case==='missing'){$this->assertNull($m['depreciation']['adjustment']);$this->assertNull($m['taxableProfit']);$this->assertNull($m['colecta']);$this->assertSame('40',$m['costs']['rows'][1]['adjustment']['numerator']);}
else{[$profit,$base,$colecta]=$expected[$case];$this->assertSame($profit,$m['taxableProfit']['numerator']);$this->assertSame($base,$m['taxableBase']['numerator']);$this->assertSame(['numerator'=>$colecta,'denominator'=>'5'],$m['colecta']);$this->assertSame([],$m['depreciation']['pending']);if($case==='prior'){$this->assertSame('20',$m['depreciation']['assets'][0]['priorUsed']['numerator']);$this->assertSame('40',$b['depreciation']['assets'][0]['priorAvailable']);}}
file_put_contents(base_path('outputs/irpc-l6-depreciation/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
}
}
}