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

52 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 IspcQuarterDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_quarter_and_option_recover_privately_without_changing_accepted_fiscal_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]);
$actor = User::factory()->create(['email_verified_at' => now()]);
$this->actingAs($actor);
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/ispc-quarter-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
$personal = ['person_type' => 'collective'];
unset($draft['person_type']);
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, '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']);
$s = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$r = $s['ispcQuarters']['opportunity:375']['result'];
$this->assertSame('calculated', $r['status']);
$this->assertSame(['numerator' => '24000', 'denominator' => '1'], $r['tax']);
$this->assertSame($r['tax'], $r['payment']);
$this->assertTrue($r['declaration']);
$this->assertFalse($r['projected']);
$this->assertSame('recorded', $r['eligibility']['optionStatus']);
$this->assertSame('SYNTHETIC QA opção ISPC2026', $r['eligibility']['input']['optionReference']);
$this->assertNotEmpty($s['ispcQuarters']['opportunity:375']['history']);
$seed = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-l3e-preserved.json')), true, flags: JSON_THROW_ON_ERROR);
foreach (json_decode($seed['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR) as $key => $value) {
$this->assertSame($value, $s[$key]);
}
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
$this->getJson('/api/v1/simulation-drafts/'.$id)->assertNotFound();
$this->actingAs($actor);
$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
if (is_dir(base_path('outputs/ispc-l4b-20261025'))) {
file_put_contents(base_path('outputs/ispc-l4b-20261025/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}