57 lines
4.0 KiB
PHP
57 lines
4.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 IvaPublicAuthorityBaseDraftTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_public_act_base_recovers_privately_without_changing_delivered_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]);
|
|
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
|
$draft = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7a-bases.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:339', $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['publicAuthorityBases']['opportunity:339'];
|
|
$this->assertCount(2, $book['rows']);
|
|
$this->assertSame(['public_authority_indemnity', 'public_authority_compensation'], array_column($book['rows'], 'treatment'));
|
|
$this->assertSame(['1500.25', '1250.30'], array_column($book['result']['rows'], 'baseAmount'));
|
|
$this->assertSame(['determined', 'determined'], array_column($book['result']['rows'], 'status'));
|
|
$this->assertSame([null, null], array_column($book['result']['rows'], 'vat'));
|
|
$this->assertSame([null, null], array_column($book['result']['rows'], 'rate'));
|
|
$this->assertSame('2026-12', $book['rows'][0]['period']);
|
|
$this->assertSame('SYNTHETIC QA acto A,operação própria', $book['rows'][0]['actRef']);
|
|
$this->assertSame('mixed', $book['rows'][1]['compensationForm']);
|
|
$this->assertSame('1000.10', $book['rows'][1]['moneyAmount']);
|
|
$this->assertSame('250.20', $book['rows'][1]['nonMoneyValue']);
|
|
$this->assertStringContainsString('valor normal', $book['rows'][1]['valuationRef']);
|
|
$this->assertStringContainsString('composição15(5)/(6)', $book['rows'][1]['compositionRef']);
|
|
$this->assertStringContainsString('15(2)(d)', $book['result']['source']);
|
|
$this->assertCount(2, $book['history']);
|
|
$this->assertNull($book['history'][0]['rows'][0]['baseAmount']);
|
|
$this->assertNull($book['history'][1]['rows'][0]['vat']);
|
|
$frozen = json_decode(file_get_contents(base_path('tests/frontend/fixtures/iva-g7a-preserved-inputs.json')), true, flags: JSON_THROW_ON_ERROR);
|
|
$prior = json_decode($frozen['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
|
|
$this->assertSame($prior, array_diff_key($store, ['publicAuthorityBases' => true]));
|
|
$this->assertSame('400.00', $store['importExemptions']['opportunity:338']['result']['rows'][1]['importVat']);
|
|
$this->assertStringContainsString('Plano de importações', $store['importExemptions']['opportunity:338']['rows'][1]['developmentPlanRef']);
|
|
$this->assertSame('0.00', $store['importExemptions']['opportunity:336']['result']['rows'][0]['serviceVat']);
|
|
$this->assertNull($store['books']['opportunity:329']['result']['periods'][0]['fields']['11']);
|
|
file_put_contents(base_path('outputs/iva-l1-g7a-public-base-20261024/recovered.json'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
}
|