Files
Investidor-V2/tests/Feature/IrpcNormalBaseDraftTest.php
T

68 lines
3.8 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 IrpcNormalBaseDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_taxable_base_and_missing_deduction_information_recover_without_consuming_loss_balances(): 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) {
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-base/'.$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('6700', $m['taxableProfit']['numerator']);
$this->assertNull($m['tax']);
$this->assertSame('IRPC-normal-adjustments/3', $m['version']);
$this->assertSame('2300', $m['base']['requestedLosses']['numerator']);
$this->assertSame('2021', $m['base']['losses'][0]['year']);
$this->assertSame(2026, $m['base']['losses'][0]['lastOrdinaryYear']);
$this->assertSame('800', $m['base']['losses'][0]['available']['numerator']);
$this->assertSame('2500', $m['base']['losses'][1]['available']['numerator']);
$this->assertSame('200', $b['base']['losses'][0]['previouslyUsed']);
$this->assertSame('500', $b['base']['losses'][1]['previouslyUsed']);
$this->assertArrayHasKey('irpcWithholdings', $s);
$this->assertSame('IRPC-normal-adjustments/2', $b['history'][1]['model']['version']);
if ($case === 'calculated') {
$this->assertSame('4400', $m['taxableBase']['numerator']);
$this->assertSame('2300', $m['base']['deductedLosses']['numerator']);
$this->assertSame('1000', $m['base']['losses'][1]['remaining']['numerator']);
$this->assertSame('known', $m['base']['input']['benefits']['state']);
$this->assertSame('0', $m['base']['input']['benefits']['amount']);
} else {
$this->assertNull($m['taxableBase']);
$this->assertNull($m['base']['deductedLosses']);
$this->assertSame('', $m['base']['input']['benefits']['state']);
}
file_put_contents(base_path('outputs/irpc-l6-base/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}