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

67 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 IrpcNormalCostsDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_cost_limits_provisions_and_timing_recover_their_facts_results_and_original_histories(): 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()]));
$expected = ['calculated' => ['6730', '4430', '7088'], 'additional' => ['7050', '4750', '1520'], 'limits' => ['7210', '4910', '7856'], 'closing' => ['6530', '4230', '6768']];
$id = null;
$etag = null;
foreach (['calculated', 'missing', 'additional', 'limits', 'closing'] as $case) {
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-costs/'.$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/6', $m['version']);
$this->assertArrayHasKey('irpcWithholdings', $s);
$this->assertArrayHasKey('books', $s);
$this->assertContains('IRPC-normal-adjustments/5', array_column(array_column($b['history'], 'model'), 'version'));
$this->assertSame($b['costs'], $m['costs']['input']);
$this->assertNull($m['tax']);
$this->assertNull($m['assessment']['finalBalance']['payable']);
$this->assertNull($m['assessment']['finalBalance']['recoverable']);
if ($case === 'missing') {
$this->assertNull($m['taxableProfit']);
$this->assertNull($m['taxableBase']);
$this->assertNull($m['colecta']);
$this->assertSame('520', $m['schedules']['net']['numerator']);
$this->assertSame('40', $m['costs']['rows'][1]['adjustment']['numerator']);
} else {
[$profit,$base,$tax] = $expected[$case];
$this->assertSame($profit, $m['taxableProfit']['numerator']);
$this->assertSame($base, $m['taxableBase']['numerator']);
$this->assertSame(['numerator' => $tax, 'denominator' => $case === 'additional' ? '1' : '5'], $m['colecta']);
$this->assertSame([], $m['costs']['pending']);
}
file_put_contents(base_path('outputs/irpc-l6-costs/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}