51 lines
3.0 KiB
PHP
51 lines
3.0 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 IrpcPecLastAmountDraftTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_pec_obligation_and_calendar_survive_native_draft_without_new_paid_deductions(): void
|
|
{
|
|
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
|
$this->assertSame('investmoz_demography_test', $target->name);
|
|
$this->assertSame(55441, (int) $target->port);
|
|
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
|
$actor = User::factory()->create();
|
|
$this->actingAs($actor);
|
|
$id = null;
|
|
$etag = null;
|
|
foreach (['documented' => 138, 'missing' => 138, 'positive' => 138, 'excess' => 138] as $name => $balance) {
|
|
$snapshot = json_decode(file_get_contents(base_path('outputs/irpc-pec-last-amount-20261113/'.$name.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
|
$personal = ['person_type' => $snapshot['person_type']];
|
|
unset($snapshot['person_type']);
|
|
$payload = ['personal_snapshot' => $personal, 'economic_snapshot' => $snapshot];
|
|
if ($id === null) {
|
|
$id = $this->postJson('/api/v1/simulation-drafts', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
|
} else {
|
|
$this->putJson('/api/v1/simulation-drafts/'.$id, $payload, ['If-Match' => $etag])->assertOk();
|
|
}
|
|
$response = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
|
|
$etag = $response->headers->get('ETag');
|
|
$back = $response->json('data.economic_snapshot');
|
|
$this->assertSame($snapshot['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
|
$book = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$snapshot['context_opportunity']];
|
|
$this->assertCount(1, $book['history']);
|
|
$this->assertSame(['numerator' => '138', 'denominator' => '1'], $book['history'][0]['model']['arithmeticBalance']);
|
|
$this->assertSame($balance === null ? null : ['numerator' => (string) $balance, 'denominator' => '1'], $book['result']['model']['arithmeticBalance']);
|
|
$this->assertSame($book['pecObligation'], $book['result']['model']['input']['pecObligation']);
|
|
$this->assertSame('42500.25', $book['pecObligation']['lastAmount']['amount']);
|
|
$this->assertSame('2024', $book['pecObligation']['lastAmount']['year']);
|
|
$this->assertSame('SYNTHETIC effective activity'.($name === 'start' ? '2026' : '2020'), $book['pecObligation']['activityReference']);
|
|
file_put_contents(base_path('outputs/irpc-pec-last-amount-20261113/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
}
|
|
}
|