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

48 lines
2.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 IrpcInterestCerDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_documented_parameter_calculation_and_segmented_cases_recover_through_private_api(): 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/irpc-interest-cer/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
$personal = ['person_type' => $draft['person_type']];
unset($draft['person_type']);
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, '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']);
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$model = $store['irpcWithholdings'][$draft['context_opportunity']]['mrftaResult']['model'];
$this->assertSame('7300', $model['principal']['numerator']);
$this->assertSame('3650', $model['paid']['numerator']);
$this->assertSame('15', $model['interest']['numerator']);
$this->assertSame('3665', $model['total']['numerator']);
$this->assertSame('IRPC-interest/1', $model['automatic']['version']);
$this->assertSame('', $model['input']['interest']['mode']);
$this->assertSame('automatic', $model['input']['interest']['calculation']);
$this->assertSame('10', $model['automatic']['rule']['annualRate']);
$this->assertStringContainsString('fictício', $model['automatic']['rule']['rateSource']);
$segments = $model['automatic']['rows'][0]['segments'];
$this->assertCount(2, $segments);
$this->assertSame(5, $segments[0]['days']);
$this->assertSame('7300', $segments[0]['principal']['numerator']);
$this->assertSame('3650', $segments[1]['principal']['numerator']);
$this->assertSame('999', $model['lines'][0]['cer']);
file_put_contents(base_path('outputs/irpc-interest-cer/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}