53 lines
2.9 KiB
PHP
53 lines
2.9 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 IrpcNationalFractionDraftTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_derived_national_fraction_round_trips_through_the_existing_private_draft_writer(): void
|
|
{
|
|
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
|
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
|
$this->assertSame(55441, (int) $target->port);
|
|
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
|
$this->actingAs(User::findOrFail(1021));
|
|
$id = null;
|
|
$etag = null;
|
|
foreach (['ordinary', 'exact', 'missing'] as $name) {
|
|
$snapshot = json_decode(file_get_contents(base_path('outputs/irpc-national-fraction-20261110/'.$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']);
|
|
$this->assertSame($snapshot['business_plan_snapshot'], $back['business_plan_snapshot']);
|
|
$book = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$snapshot['context_opportunity']];
|
|
$this->assertSame('proportional', $book['internationalCredits']['positions'][0]['nationalMethod']);
|
|
$model = $book['result']['model'];
|
|
if ($name === 'missing') {
|
|
$this->assertSame('indeterminate', $model['status']);
|
|
$this->assertNull($model['arithmeticBalance']);
|
|
} else {
|
|
$this->assertSame(['numerator' => $name === 'ordinary' ? '32' : '2', 'denominator' => $name === 'ordinary' ? '1' : '625'], $model['internationalCredit']['positions'][0]['nationalLimit']);
|
|
$this->assertSame('IRPC-national-fraction/1', $model['internationalCredit']['positions'][0]['nationalDerivation']['version']);
|
|
}
|
|
file_put_contents(base_path('outputs/irpc-national-fraction-20261110/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
}
|
|
}
|