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

85 lines
5.2 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 IrpcSpecialDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_special_treatments_recover_with_original_plan_history_and_indeterminate_cases(): 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 (['expense', 'missing', 'negative', 'absent', 'cooperative', 'acceleration'] as $case) {
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-common/'.$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['business_plan_snapshot'], $back['business_plan_snapshot']);
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$b = $s['irpcNormal'][$d['context_opportunity']];
$m = $b['result']['model'];
$l7 = $m['special'];
$this->assertSame('IRPC-normal-adjustments/10', $m['version']);
$this->assertSame($b['special'], $l7['input']);
$this->assertContains('IRPC-normal-adjustments/9', array_column(array_column($b['history'], 'model'), 'version'));
$this->assertArrayHasKey('irpcWithholdings', $s);
$this->assertArrayHasKey('books', $s);
$this->assertNull($m['tax']);
$this->assertNull($l7['finalBalance']['payable']);
$this->assertNull($l7['finalBalance']['recoverable']);
$this->assertSame('123456789', $l7['subjectNuit']);
$this->assertStringContainsString('61(4)', $l7['expenses']['source']);
if ($case === 'expense') {
$this->assertSame('35', $l7['expenses']['autonomousTax']['numerator']);
$this->assertSame('100', $l7['expenses']['rows'][0]['l6Adjustment']['numerator']);
$this->assertSame('0', $l7['expenses']['rows'][0]['additionalProfitAdjustment']['numerator']);
$this->assertSame($m['taxableProfit'], $l7['taxableProfit']);
$this->assertSame(['numerator' => '5343', 'denominator' => '5'], $l7['combinedColecta']);
} elseif ($case === 'missing') {
$this->assertSame('indeterminate', $l7['expenses']['status']);
$this->assertNull($l7['expenses']['autonomousTax']);
$this->assertNull($l7['combinedColecta']);
$this->assertSame('3230', $m['taxableProfit']['numerator']);
} elseif ($case === 'negative') {
$this->assertSame('not_applicable', $l7['expenses']['rows'][0]['status']);
$this->assertSame('0', $l7['expenses']['autonomousTax']['numerator']);
} elseif ($case === 'absent') {
$this->assertSame('absent', $l7['expenses']['status']);
$this->assertSame('0', $l7['expenses']['autonomousTax']['numerator']);
} elseif ($case === 'cooperative') {
$this->assertSame('16', $l7['cooperative']['rate']['numerator']);
$this->assertSame(['numerator' => '2504', 'denominator' => '5'], $l7['colecta']);
$this->assertSame(['numerator' => '5008', 'denominator' => '5'], $m['colecta']);
} else {
$this->assertSame('20', $l7['acceleration']['additionalDeduction']['numerator']);
$this->assertSame('150', $l7['acceleration']['accelerated']['assets'][0]['quota']['numerator']);
$this->assertSame('120', $l7['acceleration']['accelerated']['assets'][0]['deduction']['numerator']);
$this->assertSame('6240', $l7['taxableProfit']['numerator']);
$this->assertSame('6260', $m['taxableProfit']['numerator']);
$this->assertSame($b['depreciation'], $l7['acceleration']['accelerated']['input']);
}
file_put_contents(base_path('outputs/irpc-l7-common/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}