Files
Investidor-V2/tests/Feature/IrpcNormalProfitDraftTest.php
2026-10-25 21:33:51 +02:00

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 IrpcNormalProfitDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_scoped_taxable_profit_and_missing_information_recover_with_all_prior_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()]));
$id=null;$etag=null;
foreach(['calculated','missing'] as $case){
$draft=json_decode(file_get_contents(base_path('outputs/irpc-l6-profit/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
$personal=['person_type'=>$draft['person_type']];unset($draft['person_type']);
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$draft],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$draft],['If-Match'=>$etag])->assertOk();
$response=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$response->headers->get('ETag');$recovered=$response->json('data.economic_snapshot');
$this->assertSame($draft['modelo_a_snapshot'],$recovered['modelo_a_snapshot']);
$this->assertSame($draft['business_plan_snapshot'],$recovered['business_plan_snapshot']);
$store=json_decode($recovered['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
$book=$store['irpcNormal'][$draft['context_opportunity']];$m=$book['result']['model'];
$this->assertSame('6480',$m['accountingProfit']['numerator']);
$this->assertSame('220',$m['additions']['numerator']);
$this->assertNull($m['taxableBase']);$this->assertNull($m['tax']);
$this->assertSame('IRPC-normal-adjustments/2',$m['version']);
$this->assertSame('projected',$m['origin']);
$this->assertSame('absent',$m['profit']['input']['topics']['positivePatrimonial']['state']);
$this->assertCount(6,$m['profit']['lines']);
$this->assertSame('known',$m['profit']['input']['topics']['incomeCorrections']['state']);
$this->assertSame('0',$m['profit']['input']['topics']['incomeCorrections']['amount']);
$this->assertArrayHasKey('irpcWithholdings',$store);
$this->assertSame('IRPC-normal-adjustments/1',$book['history'][0]['model']['version']);
if($case==='calculated'){$this->assertSame('6700',$m['taxableProfit']['numerator']);$this->assertCount(0,$m['profit']['pending']);}
else{$this->assertNull($m['taxableProfit']);$this->assertSame('',$m['profit']['input']['topics']['negativePatrimonial']['state']);}
file_put_contents(base_path('outputs/irpc-l6-profit/recovered-'.$case.'.json'),json_encode($recovered,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
}
}
}