53 lines
3.4 KiB
PHP
53 lines
3.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 IvaTemporaryBenefitDraftTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_cessation_and_explicit_continuations_recover_with_their_opportunity_and_history(): 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-l1-g3-temporary-20261024/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']);
|
|
$this->assertSame('opportunity:322', $recovered['context_opportunity']);
|
|
$this->assertSame('Manica', $recovered['selection_labels']['province_id']);
|
|
$store = json_decode($recovered['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
|
$book = $store['salesOperations']['opportunity:322'];
|
|
$this->assertSame('opportunity:322', $book['result']['opportunity']);
|
|
$this->assertSame('MZN', $book['result']['currency']);
|
|
$this->assertSame('2026-10', $book['result']['periods'][0]['period']);
|
|
$this->assertSame('700.00', $book['result']['periods'][0]['fields']['01']);
|
|
$this->assertSame('112.00', $book['result']['periods'][0]['fields']['02']);
|
|
$this->assertSame('100.00', $book['result']['periods'][0]['fields']['05']);
|
|
$this->assertCount(8, $book['rows']);
|
|
$this->assertSame('116', $book['rows'][0]['amount']);
|
|
$this->assertSame('included', $book['rows'][0]['basis']);
|
|
$this->assertSame('temporary_sugar', $book['rows'][0]['temporaryBenefitOrigin']);
|
|
$this->assertSame('temporary_solar_inputs', $book['rows'][6]['temporaryBenefitOrigin']);
|
|
$this->assertSame('production_agriculture', $book['rows'][7]['treatment']);
|
|
$this->assertStringContainsString('P045', $book['rows'][6]['source']);
|
|
$this->assertCount(7, $book['history'][0]['rows']);
|
|
$this->assertNull($book['history'][0]['periods'][0]['fields']['01']);
|
|
$this->assertStringContainsString('terminou em31/12/2025', $book['history'][0]['rows'][0]['reason']);
|
|
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-annex-i-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
|
foreach (json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['salesOperations'] as $context => $original) {
|
|
$this->assertSame($original, $store['salesOperations'][$context]);
|
|
}
|
|
file_put_contents(base_path('outputs/iva-l1-g3-temporary-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
}
|