fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
@@ -13,37 +14,75 @@ final class IrpcSpecialStartPeriodDraftTest extends TestCase
|
||||
|
||||
public function test_start_period_cbf16_recovers_new_results_missing_cases_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()]));$id=null;$etag=null;
|
||||
foreach(['start','fraction','missing','negative','absent']as$case){
|
||||
$d=json_decode(file_get_contents(base_path('outputs/irpc-l7-start-period/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
|
||||
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
|
||||
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
|
||||
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'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'];$a=$m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/12',$m['version']);$this->assertSame($b['special']['acceleration']['monthly'],$a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/11',array_column(array_column($b['history'],'model'),'version'));$this->assertContains('IRPC-normal-adjustments/10',array_column(array_column($b['history'],'model'),'version'));
|
||||
$this->assertSame($b['depreciation'],$a['normal']['input']);$this->assertSame('L8',$m['special']['finalBalance']['scope']);$this->assertNull($m['special']['finalBalance']['payable']);
|
||||
$this->assertNull($m['special']['finalBalance']['recoverable']);$this->assertNull($m['tax']);$this->assertArrayHasKey('irpcWithholdings',$s);
|
||||
if($case==='start'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(6,$v['months']);$this->assertSame('50',$v['normalQuota']['numerator']);$this->assertSame('75',$v['acceleratedQuota']['numerator']);
|
||||
$this->assertSame('60',$v['acceleratedDeduction']['numerator']);$this->assertSame('10',$a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertSame('3120',$m['special']['taxableProfit']['numerator']);$this->assertSame(['numerator'=>'4992','denominator'=>'5'],$m['special']['colecta']);$this->assertTrue($m['periodsFx']['short']);$this->assertSame('2026-07-01',$a['monthly']['period']['from']);$this->assertStringContainsString('início de actividade',$a['source']);
|
||||
$this->assertSame($b['depreciation'],$a['accelerated']['input']);
|
||||
}elseif($case==='fraction'){
|
||||
$v=$a['monthly']['assets'][0];$this->assertSame(1,$v['months']);$this->assertSame(['numerator'=>'25','denominator'=>'3'],$v['normalQuota']);$this->assertSame(['numerator'=>'5','denominator'=>'3'],$a['additionalDeduction']);
|
||||
}elseif($case==='missing'){
|
||||
$this->assertSame('indeterminate',$a['status']);$this->assertNull($a['additionalDeduction']);$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertNull($m['special']['colecta']);
|
||||
}elseif($case==='negative'){
|
||||
$this->assertSame('not_applicable',$a['rows'][0]['status']);$this->assertFalse($a['monthly']['assets'][0]['applied']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
}else{
|
||||
$this->assertSame('absent',$a['status']);$this->assertSame([],$a['monthly']['assets']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
|
||||
$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 (['start', 'fraction', 'missing', 'negative', 'absent'] as $case) {
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-start-period/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
if ($id === null) {
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
} else {
|
||||
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-start-period/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
|
||||
$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'];
|
||||
$a = $m['special']['acceleration'];
|
||||
$this->assertSame('IRPC-normal-adjustments/12', $m['version']);
|
||||
$this->assertSame($b['special']['acceleration']['monthly'], $a['monthly']['input']);
|
||||
$this->assertContains('IRPC-normal-adjustments/11', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertContains('IRPC-normal-adjustments/10', array_column(array_column($b['history'], 'model'), 'version'));
|
||||
$this->assertSame($b['depreciation'], $a['normal']['input']);
|
||||
$this->assertSame('L8', $m['special']['finalBalance']['scope']);
|
||||
$this->assertNull($m['special']['finalBalance']['payable']);
|
||||
$this->assertNull($m['special']['finalBalance']['recoverable']);
|
||||
$this->assertNull($m['tax']);
|
||||
$this->assertArrayHasKey('irpcWithholdings', $s);
|
||||
if ($case === 'start') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(6, $v['months']);
|
||||
$this->assertSame('50', $v['normalQuota']['numerator']);
|
||||
$this->assertSame('75', $v['acceleratedQuota']['numerator']);
|
||||
$this->assertSame('60', $v['acceleratedDeduction']['numerator']);
|
||||
$this->assertSame('10', $a['additionalDeduction']['numerator']);
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
$this->assertSame('3120', $m['special']['taxableProfit']['numerator']);
|
||||
$this->assertSame(['numerator' => '4992', 'denominator' => '5'], $m['special']['colecta']);
|
||||
$this->assertTrue($m['periodsFx']['short']);
|
||||
$this->assertSame('2026-07-01', $a['monthly']['period']['from']);
|
||||
$this->assertStringContainsString('início de actividade', $a['source']);
|
||||
$this->assertSame($b['depreciation'], $a['accelerated']['input']);
|
||||
} elseif ($case === 'fraction') {
|
||||
$v = $a['monthly']['assets'][0];
|
||||
$this->assertSame(1, $v['months']);
|
||||
$this->assertSame(['numerator' => '25', 'denominator' => '3'], $v['normalQuota']);
|
||||
$this->assertSame(['numerator' => '5', 'denominator' => '3'], $a['additionalDeduction']);
|
||||
} elseif ($case === 'missing') {
|
||||
$this->assertSame('indeterminate', $a['status']);
|
||||
$this->assertNull($a['additionalDeduction']);
|
||||
$this->assertSame('3130', $m['taxableProfit']['numerator']);
|
||||
$this->assertNull($m['special']['colecta']);
|
||||
} elseif ($case === 'negative') {
|
||||
$this->assertSame('not_applicable', $a['rows'][0]['status']);
|
||||
$this->assertFalse($a['monthly']['assets'][0]['applied']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
} else {
|
||||
$this->assertSame('absent', $a['status']);
|
||||
$this->assertSame([], $a['monthly']['assets']);
|
||||
$this->assertSame('0', $a['additionalDeduction']['numerator']);
|
||||
}
|
||||
file_put_contents(base_path('outputs/irpc-l7-start-period/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user