44 lines
2.4 KiB
PHP
44 lines
2.4 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 IvaAcquisitionRightDraftTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_right_recovers_with_sources_totals_history_and_preserved_books(): 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/iva-l2-a-20261025/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
|
|
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], '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);
|
|
$book = $store['books']['opportunity:368'];
|
|
$this->assertCount(5, $book['rows']);
|
|
$this->assertSame(['eligible', 'eligible', 'eligible', 'no_right', 'no_right'], array_column(array_column($book['result']['rows'], 'eligibility'), 'status'));
|
|
$this->assertSame('48.00', $book['result']['periods'][0]['fields']['15']);
|
|
$this->assertCount(1, $book['history']);
|
|
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l2a-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
|
|
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $map) {
|
|
if ($key === 'version') {
|
|
continue;
|
|
}
|
|
foreach ($map as $context => $original) {
|
|
$this->assertSame($original, $store[$key][$context]);
|
|
}
|
|
}
|
|
file_put_contents(base_path('outputs/iva-l2-a-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
}
|