commit correcoes
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\DevelopmentCorridor;
|
||||
use App\Models\InvestmentDossier;
|
||||
use App\Models\Project;
|
||||
use App\Models\Sector;
|
||||
use App\Models\User;
|
||||
use App\Support\IsolatedQaDatabase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class GlobalSearchCountTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_licensing_question_opens_existing_guidance_without_mixing_catalogue_matches(): void
|
||||
{
|
||||
$this->withoutVite();
|
||||
$this->get('/pesquisa?'.http_build_query(['q' => 'como licenciar uma empresa']))->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->where('answer.type', 'guide')->where('results.total', 2)
|
||||
->where('results.data.0.url', '/como-investir#planeamento')
|
||||
->where('results.data.1.url', '/investimentos/iniciar?step=S08'));
|
||||
}
|
||||
|
||||
public function test_physical_product_search_keeps_the_product_and_documented_location_in_its_link(): void
|
||||
{
|
||||
$this->assertTrue(IsolatedQaDatabase::allowsSchemaChanges());
|
||||
$this->withoutVite();
|
||||
config(['portal.legacy_content_enabled' => false, 'portal.legacy_content_qa_enabled' => false]);
|
||||
$sector = Sector::firstOrCreate(['slug' => 'mineracao'], ['name' => 'Mineração']);
|
||||
$sector->forceFill(['is_active' => true, 'published_at' => now()->subMinute()])->save();
|
||||
$this->get('/pesquisa?'.http_build_query(['q' => 'onde encontrar grafite em Cabo Delgado']))->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->where('answer.type', 'products')->where('results.total', 1)->where('results.unavailable', [])
|
||||
->where('results.data.0.title', 'Grafite')->where('results.data.0.category', 'Produtos e localizações')
|
||||
->where('results.data.0.location', fn ($text) => str_contains($text, 'Cabo Delgado'))
|
||||
->where('results.data.0.url', fn ($url) => str_contains($url, 'resource_group=') && str_contains($url, 'resource_location=Cabo+Delgado')));
|
||||
$this->get('/pesquisa?'.http_build_query(['q' => 'grafite Cabo Delgado', 'category' => 'physical']))->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->where('answer.category', 'physical')->where('results.total', 1)
|
||||
->where('results.data.0.category', 'Produtos e localizações'));
|
||||
$this->get('/pesquisa?category=invalid')->assertRedirect();
|
||||
}
|
||||
|
||||
public function test_financial_product_search_excludes_drafts_and_future_publications_and_distinguishes_coverage(): void
|
||||
{
|
||||
$this->assertTrue(IsolatedQaDatabase::allowsSchemaChanges());
|
||||
$this->withoutVite();
|
||||
if (! Schema::hasTable('funding_programmes')) {
|
||||
// Only this transaction in the isolated QA database; no active schema changes.
|
||||
(require database_path('migrations/2026_11_02_210000_funding_programme_catalogue.php'))->up();
|
||||
}
|
||||
$actor = User::factory()->create();
|
||||
$marker = 'SYNTHFIN'.Str::random(8);
|
||||
foreach (['published', 'draft', 'future', 'historical', 'merged'] as $state) {
|
||||
$id = (string) Str::uuid();
|
||||
$version = (string) Str::uuid();
|
||||
$payload = json_encode(['title' => $marker.' '.$state, 'kind' => 'institution', 'summary' => 'Nota de preparação: ficha e documento gerador.',
|
||||
'institution_nature' => 'bank', 'institution_services' => ['investment'],
|
||||
'institution_status' => in_array($state, ['historical', 'merged'], true) ? $state : 'reported',
|
||||
'locations' => [['location_text' => 'Nampula']], 'products' => [['title' => 'Crédito PME', 'coverage' => 'national', 'needs' => ['investment']]]], JSON_THROW_ON_ERROR);
|
||||
DB::table('funding_programmes')->insert(['id' => $id, 'code' => $marker.$state, 'draft' => $payload, 'created_by' => $actor->id]);
|
||||
DB::table('funding_programme_versions')->insert(['id' => $version, 'programme_id' => $id, 'version' => 1, 'payload' => $payload,
|
||||
'reason' => 'Synthetic QA only', 'actor_id' => $actor->id, 'published_at' => $state === 'future' ? now()->addDay() : now()->subMinute()]);
|
||||
if ($state !== 'draft') {
|
||||
DB::table('funding_programmes')->where('id', $id)->update(['published_version_id' => $version]);
|
||||
}
|
||||
}
|
||||
$this->get('/pesquisa?'.http_build_query(['q' => 'produtos financeiros '.$marker.' em Nampula']))->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->where('answer.type', 'products')->where('results.total', 1)->where('results.unavailable', [])
|
||||
->where('results.data.0.category', 'Produtos financeiros')->where('results.data.0.description', 'Crédito PME')
|
||||
->where('results.data.0.location', 'Presença física: Nampula')
|
||||
->where('results.data.0.coverage', fn ($text) => str_contains($text, 'nacional')));
|
||||
}
|
||||
|
||||
public function test_corridor_count_excludes_other_types_drafts_and_deleted_entities(): void
|
||||
{
|
||||
$this->assertTrue(IsolatedQaDatabase::allowsSchemaChanges());
|
||||
$this->withoutVite();
|
||||
$marker = 'SYNTHCOUNT'.Str::random(10);
|
||||
foreach (range(1, 4) as $n) {
|
||||
$corridor = DevelopmentCorridor::create(['code' => $marker.$n, 'name' => $marker.$n, 'status' => 'active', 'data_classification' => 'public']);
|
||||
InvestmentDossier::create(['corridor_id' => $corridor->id, 'title' => $marker.' '.$n,
|
||||
'content' => [], 'source' => 'Synthetic QA only', 'publication_status' => $n === 3 ? 'draft' : 'published',
|
||||
'published_at' => now()->subMinute(), 'approval_basis' => 'document_owner', 'approval_evidence' => 'Synthetic QA only']);
|
||||
if ($n === 4) {
|
||||
$corridor->delete();
|
||||
}
|
||||
}
|
||||
InvestmentDossier::create(['project_id' => Project::factory()->create()->id, 'title' => $marker.' corredor relacionado',
|
||||
'content' => [], 'source' => 'Synthetic QA only', 'publication_status' => 'published', 'published_at' => now(),
|
||||
'approval_basis' => 'document_owner', 'approval_evidence' => 'Synthetic QA only']);
|
||||
$query = 'quantos corredores existem '.$marker;
|
||||
$this->get('/pesquisa?'.http_build_query(['q' => $query]))->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->component('portal/search')->where('query', $query)->where('answer.count', 2)->where('answer.label', 'corredores')
|
||||
->where('results.total', 2)->has('results.data', 2)->where('results.unavailable', []));
|
||||
$this->get('/pesquisa?'.http_build_query(['q' => 'quantos corredores existem '.$marker.' inexistente']))
|
||||
->assertOk()->assertInertia(fn (Assert $page) => $page->where('answer.count', 0)->where('results.total', 0));
|
||||
$this->get('/pesquisa?q=quantos+corredores+existem')->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->where('answer.label', 'corredores')->where('answer.count', fn ($count) => $count >= 2)
|
||||
->where('results.unavailable', []));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Services\FederatedSearch;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class GlobalSearchTest extends TestCase
|
||||
@@ -35,6 +36,18 @@ final class GlobalSearchTest extends TestCase
|
||||
$this->assertSame('Como investir', $result['data'][0]['title']);
|
||||
}
|
||||
|
||||
public function test_unavailable_public_reference_does_not_hide_other_sources_or_swallow_forbidden_access(): void
|
||||
{
|
||||
$result = app(FederatedSearch::class)->page([
|
||||
'Referências' => fn () => throw new HttpException(503),
|
||||
'Páginas' => fn () => ['count' => 1, 'fetch' => fn () => [['title' => 'Como investir', 'url' => '/como-investir']]],
|
||||
], 1);
|
||||
$this->assertSame(1, $result['total']);
|
||||
$this->assertSame(['Referências'], $result['unavailable']);
|
||||
$this->expectException(HttpException::class);
|
||||
app(FederatedSearch::class)->page(['Restrito' => fn () => throw new HttpException(403)], 1);
|
||||
}
|
||||
|
||||
public function test_public_search_uses_the_existing_portfolio_visibility_scope(): void
|
||||
{
|
||||
if (getenv('GLOBAL_SEARCH_QA') !== '1') {
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\InvestmentZone;
|
||||
use App\Models\User;
|
||||
use App\Services\InvestmentMapIndicators;
|
||||
use App\Services\InvestmentZoneIntegralDetails;
|
||||
use App\Services\InvestmentZoneOperationalDetails;
|
||||
use App\Services\InvestmentZoneOperationalProfile;
|
||||
use App\Support\IsolatedQaDatabase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestmentObservationNatureTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->assertTrue(IsolatedQaDatabase::allowsSchemaChanges());
|
||||
Http::preventStrayRequests();
|
||||
}
|
||||
|
||||
private function observation(?string $kind): array
|
||||
{
|
||||
$item = ['id' => (string) Str::uuid(), 'label' => 'SYNTHETIC nature QA', 'description' => 'Synthetic source only.',
|
||||
'indicator' => 'employment', 'value' => '0', 'unit' => 'pessoas', 'period_start' => '2025-01-01', 'period_end' => '2025-12-31',
|
||||
'scope' => 'Synthetic zone', 'population' => 'Synthetic establishments', 'methodology' => 'Synthetic register',
|
||||
'source_reference' => 'SYNTHETIC source; not real statistics', 'source_date' => '2026-01-15', 'knowledge' => 'documented', 'disclosure' => true];
|
||||
|
||||
return $kind === null ? $item : [...$item, 'measure_kind' => $kind];
|
||||
}
|
||||
|
||||
private function zone(): InvestmentZone
|
||||
{
|
||||
$actor = User::factory()->create(['email' => 'measure-'.Str::uuid().'@example.test']);
|
||||
|
||||
return InvestmentZone::create(['code' => 'MEASURE-QA-'.Str::uuid(), 'category' => 'industrial_park', 'name' => 'SYNTHETIC nature QA',
|
||||
'editor_id' => $actor->id, 'publication_status' => 'draft', 'validation_status' => 'pending']);
|
||||
}
|
||||
|
||||
public function test_explicit_natures_persist_recover_and_project_without_inference_or_private_disclosure(): void
|
||||
{
|
||||
$zone = $this->zone();
|
||||
$service = app(InvestmentZoneIntegralDetails::class);
|
||||
$ops = app(InvestmentZoneOperationalDetails::class);
|
||||
$rows = array_map(fn ($kind) => $this->observation($kind), ['observed', 'planned', 'projected', null]);
|
||||
$hidden = [...$this->observation('observed'), 'disclosure' => false, 'source_reference' => 'PRIVATE-NATURE-SOURCE'];
|
||||
$merged = $service->merge($zone, [], ['observations' => [...$rows, $hidden]]);
|
||||
$zone->forceFill(['operational_details' => $ops->pack(['integral' => $merged])])->save();
|
||||
$saved = $zone->fresh();
|
||||
$before = $saved->getRawOriginal('operational_details');
|
||||
$recovered = $ops->recover($saved)['integral']['observations'];
|
||||
$this->assertSame(['observed', 'planned', 'projected'], array_column(array_slice($recovered, 0, 3), 'measure_kind'));
|
||||
$this->assertArrayNotHasKey('measure_kind', $recovered[3]);
|
||||
$this->assertSame('0', $recovered[0]['value']);
|
||||
$view = app(InvestmentMapIndicators::class)->forZones(collect([$saved]));
|
||||
$this->assertSame(['observed', 'planned', 'projected', 'unknown'], array_column($view['records'], 'measure_kind'));
|
||||
$this->assertSame(['0', '0', '0', '0'], array_column($view['records'], 'value'));
|
||||
$this->assertStringNotContainsString('PRIVATE-NATURE-SOURCE', json_encode($view, JSON_THROW_ON_ERROR));
|
||||
$this->assertSame($before, $zone->fresh()->getRawOriginal('operational_details'));
|
||||
$this->assertSame(1, $zone->fresh()->version_no);
|
||||
}
|
||||
|
||||
public function test_invalid_nature_is_rejected_and_an_omitted_nature_does_not_erase_an_explicit_choice(): void
|
||||
{
|
||||
$zone = $this->zone();
|
||||
$service = app(InvestmentZoneIntegralDetails::class);
|
||||
$row = $this->observation('observed');
|
||||
$before = $service->merge($zone, [], ['observations' => [$row]]);
|
||||
$withoutKind = $row;
|
||||
unset($withoutKind['measure_kind']);
|
||||
$recovered = $service->merge($zone, $before, ['observations' => [$withoutKind]]);
|
||||
$this->assertSame('observed', $recovered['observations'][0]['measure_kind']);
|
||||
$changed = $service->merge($zone, $before, ['observations' => [[...$row, 'measure_kind' => 'planned']]]);
|
||||
$this->assertSame('planned', $changed['observations'][0]['measure_kind']);
|
||||
$this->assertSame('observed', $before['observations'][0]['measure_kind']);
|
||||
try {
|
||||
$service->merge($zone, $before, ['observations' => [[...$row, 'measure_kind' => 'inferred_from_description']]]);
|
||||
$this->fail('Invalid nature accepted');
|
||||
} catch (ValidationException $error) {
|
||||
$this->assertArrayHasKey('observations.0.measure_kind', $error->errors());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_nature_change_stays_in_private_preparation_with_history_until_existing_editorial_review(): void
|
||||
{
|
||||
$zone = $this->zone();
|
||||
$ops = app(InvestmentZoneOperationalDetails::class);
|
||||
$row = $this->observation('observed');
|
||||
$fields = app(InvestmentZoneIntegralDetails::class)->merge($zone, [], ['observations' => [$row]]);
|
||||
// Synthetic public snapshot only, inside the rolled-back QA transaction.
|
||||
$zone->forceFill(['publication_status' => 'published', 'validation_status' => 'validated',
|
||||
'reviewer_id' => User::factory()->create(['email' => 'nature-review-'.Str::uuid().'@example.test'])->id,
|
||||
'published_at' => now(), 'physical_category' => 'industrial_park',
|
||||
'source_evidence' => [['source_type' => 'promoter', 'title' => 'SYNTHETIC QA only', 'url' => 'https://example.invalid/qa', 'supports' => 'Synthetic test fixture']],
|
||||
'operational_details' => $ops->pack(['integral' => $fields])])->save();
|
||||
$original = $zone->fresh()->getRawOriginal('operational_details');
|
||||
$profile = app(InvestmentZoneOperationalProfile::class);
|
||||
$prepared = $profile->prepare($zone->fresh(), ['version_no' => 1,
|
||||
'operational_details' => ['integral' => ['observations' => [[...$row, 'measure_kind' => 'planned']]]]], $zone->editor_id);
|
||||
$this->assertSame($original, $prepared->getRawOriginal('operational_details'));
|
||||
$this->assertSame('observed', $ops->publicData($prepared)['integral']['observations'][0]['measure_kind']);
|
||||
$this->assertSame('planned', $profile->draft($prepared)['fields']['operational_details']['integral']['observations'][0]['measure_kind']);
|
||||
$this->assertSame(1, $prepared->version_no);
|
||||
$this->assertSame(1, DB::table('investment_zone_revisions')->where('zone_id', $zone->id)->where('action', 'profile_prepared')->count());
|
||||
$this->assertSame(1, DB::table('audit_events')->where('entity_id', $zone->id)->where('action', 'profile_prepared')->count());
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,62 @@ class InvestmentPreparationWorkspaceTest extends TestCase
|
||||
return $this->postJson('/investimentos/'.$this->caseId.'/preparacao', ['version' => $view['version'], 'operation_key' => (string) Str::uuid(), 'reason' => 'SYNTHETIC explicit review, not real external action', 'action' => $action, ...$data])->assertOk()->json();
|
||||
}
|
||||
|
||||
public function test_dossier_reports_recover_preserved_exports_and_keep_financial_sources_private(): void
|
||||
{
|
||||
$view = $this->workspace();
|
||||
$view = $this->action($view, 'apiex_review', ['fingerprint' => $view['api_fingerprint']]);
|
||||
$view = $this->action($view, 'apiex_export');
|
||||
$export = $view['apiex']['exports'][0]['id'];
|
||||
$draft = (string) Str::uuid(); $report = (string) Str::uuid(); $simulation = (string) Str::uuid();
|
||||
$source = ['simulation_id' => $simulation, 'report_id' => $report, 'report_version_no' => 2, 'report_sha256' => str_repeat('a', 64), 'report_snapshot' => ['private' => 'SYNTHETIC NEVER EXPOSED'], 'consented_at' => now()->toIso8601String()];
|
||||
$otherReport = (string) Str::uuid();
|
||||
$otherSource = [...$source, 'report_id' => $otherReport, 'association_opportunity' => 'other-opportunity'];
|
||||
\App\Models\SimulationFormDraft::create(['id' => $draft, 'owner_user_id' => $this->owner->id,
|
||||
'create_key_hash' => hash('sha256', $draft), 'create_payload_hash' => hash('sha256', $draft), 'snapshot_sha256' => hash('sha256', $draft),
|
||||
'personal_snapshot' => \App\Models\SimulationFormDraft::encryptSnapshot([]),
|
||||
'economic_snapshot' => \App\Models\SimulationFormDraft::encryptSnapshot(['purpose' => 'request_support', 'simulation_sources' => [$source, $otherSource]])]);
|
||||
DB::table('desk_cases')->where('id', $this->caseId)->update(['simulation_id' => $draft]);
|
||||
$land = \App\Models\LandAssistanceCase::create(['user_id' => $this->owner->id, 'reference' => 'QA-'.Str::uuid(), 'crm_submission_key' => (string) Str::uuid(),
|
||||
'version' => 3, 'payload' => ['investor_path_case_id' => $this->caseId]]);
|
||||
$before = DB::table('simulation_form_drafts')->where('id', $draft)->first();
|
||||
$data = $this->getJson('/investimentos/'.$this->caseId)->assertOk()->json();
|
||||
$this->assertSame($this->caseId, $data['preparation_report']['case_id']);
|
||||
$this->assertSame($export, $data['preparation_report']['exports'][0]['id']);
|
||||
$this->assertStringContainsString('/investimentos/'.$this->caseId.'/preparacao/exportar/'.$export, $data['preparation_report']['exports'][0]['href']);
|
||||
$this->assertSame($report, $data['fiscal_reports'][0]['report_id']);
|
||||
$this->assertCount(1, $data['fiscal_reports']);
|
||||
$this->assertSame('/investidor/terra-duat/'.$land->id.'/imprimir', $data['land_report']['href']);
|
||||
$this->assertStringNotContainsString('SYNTHETIC NEVER EXPOSED', json_encode($data, JSON_THROW_ON_ERROR));
|
||||
$download = $this->get('/investimentos/'.$this->caseId.'/relatorios/fiscais/'.$report)->assertOk()
|
||||
->assertHeader('Cache-Control', 'no-store, private')->assertJsonPath('case_id', $this->caseId)->assertJsonPath('report_snapshot.private', 'SYNTHETIC NEVER EXPOSED')->assertJsonPath('scope_state', 'unconfirmed');
|
||||
$this->assertSame($download->getContent(), $this->get('/investimentos/'.$this->caseId.'/relatorios/fiscais/'.$report)->assertOk()->getContent());
|
||||
$this->get('/investimentos/'.$this->caseId.'/relatorios/fiscais/'.Str::uuid())->assertNotFound();
|
||||
$this->get('/investimentos/'.$this->caseId.'/relatorios/fiscais/'.$otherReport)->assertNotFound();
|
||||
$this->assertEquals($before, DB::table('simulation_form_drafts')->where('id', $draft)->first());
|
||||
$this->getJson('/investimentos/'.$this->caseId.'?opportunity=other-opportunity')->assertUnprocessable();
|
||||
$this->getJson('/investimentos/'.$this->caseId)->assertOk()->assertJsonPath('preparation_report.exports.0.id', $export)->assertJsonPath('fiscal_reports.0.report_id', $report);
|
||||
$drafts = app(\App\Services\SimulationFormDrafts::class);
|
||||
$current = \App\Models\SimulationFormDraft::findOrFail($draft);
|
||||
$request = \Illuminate\Http\Request::create('/api/v1/simulation-drafts/'.$draft.'/simulations', 'POST');
|
||||
$request->setUserResolver(fn () => $this->owner);
|
||||
$request->headers->set('If-Match', $drafts->etag($current));
|
||||
$newSource = [...$source, 'simulation_id' => (string) Str::uuid(), 'report_id' => (string) Str::uuid()];
|
||||
\App\Models\Simulation::create(['id' => $newSource['simulation_id'], 'owner_user_id' => $this->owner->id, 'status' => 'completed', 'input_snapshot' => ['synthetic' => true]]);
|
||||
$attached = $drafts->attachSimulation($draft, $newSource, $request);
|
||||
$saved = \App\Models\SimulationFormDraft::decryptSnapshot($attached['draft']->economic_snapshot)['simulation_sources'];
|
||||
$this->assertSame($source, $saved[0]);
|
||||
$this->assertArrayHasKey('association_opportunity', $saved[2]);
|
||||
$this->assertNull($saved[2]['association_opportunity']);
|
||||
$this->assertTrue($drafts->attachSimulation($draft, $newSource, $request)['replayed']);
|
||||
config(['investor-path.enabled' => false]);
|
||||
$this->get('/investimentos/'.$this->caseId.'/relatorios/fiscais/'.$report)->assertNotFound();
|
||||
config(['investor-path.enabled' => true]);
|
||||
$manager = User::factory()->create(); config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->getJson('/investimentos/'.$this->caseId)->assertOk()->assertJsonPath('fiscal_reports', [])->assertJsonPath('results', [])->assertJsonPath('land_report', null);
|
||||
$this->get('/investimentos/'.$this->caseId.'/relatorios/fiscais/'.$report)->assertForbidden();
|
||||
$this->actingAs(User::factory()->create())->getJson('/investimentos/'.$this->caseId)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_apiex_existing_dossier_requirements_review_zip_and_external_delivery_without_submission_or_approval(): void
|
||||
{
|
||||
$before = DB::table('journey_steps')->orderBy('id')->get()->toJson();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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 IrpcAdvanceCashflowDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_pec_obligation_and_calendar_survive_native_draft_without_new_paid_deductions(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('investmoz_demography_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$actor = User::factory()->create();
|
||||
$this->actingAs($actor);
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['overlap' => 138, 'distributed' => 138, 'partial' => 138, 'zero' => 138] as $name => $balance) {
|
||||
$snapshot = json_decode(file_get_contents(base_path('outputs/irpc-cashflow-group-20261113/'.$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']);
|
||||
$book = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$snapshot['context_opportunity']];
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame(['numerator' => '138', 'denominator' => '1'], $book['history'][0]['model']['arithmeticBalance']);
|
||||
$this->assertSame($balance === null ? null : ['numerator' => (string) $balance, 'denominator' => '1'], $book['result']['model']['arithmeticBalance']);
|
||||
$this->assertSame($book['pecObligation'], $book['result']['model']['input']['pecObligation']);
|
||||
$this->assertSame($book['ppcObligation'], $book['result']['model']['input']['ppcObligation']);
|
||||
$this->assertSame('2026', $book['ppcObligation']['year']);
|
||||
$this->assertSame('SYNTHETIC effective activity'.($name === 'start' ? '2026' : '2020'), $book['pecObligation']['activityReference']);
|
||||
file_put_contents(base_path('outputs/irpc-cashflow-group-20261113/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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 IrpcAdvancePeriodDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_period_survives_native_recovery_without_changing_the_independent_annual_result(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('investmoz_demography_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$actor = User::factory()->create();
|
||||
$this->actingAs($actor);
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['ordinary', 'noncivil', 'short', 'start'] as $name) {
|
||||
$snapshot = json_decode(file_get_contents(base_path('outputs/irpc-period-consistency-20261113/'.$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']);
|
||||
$book = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$snapshot['context_opportunity']];
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertArrayHasKey('advancePeriod', $book['result']['model']);
|
||||
$this->assertSame($book['history'][0]['model']['arithmeticBalance'], $book['result']['model']['arithmeticBalance']);
|
||||
$this->assertSame($book['pecObligation'], $book['result']['model']['input']['pecObligation']);
|
||||
$this->assertSame($book['ppcObligation'], $book['result']['model']['input']['ppcObligation']);
|
||||
$this->assertSame('2026', $book['ppcObligation']['year']);
|
||||
$this->assertSame('SYNTHETIC effective activity'.($name === 'start' ? '2026' : '2020'), $book['pecObligation']['activityReference']);
|
||||
file_put_contents(base_path('outputs/irpc-period-consistency-20261113/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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 IrpcAnnualNoncivilDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_period_survives_native_recovery_without_changing_the_independent_annual_result(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('investmoz_demography_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$actor = User::factory()->create();
|
||||
$this->actingAs($actor);
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['three', 'single', 'missing', 'changed'] as $name) {
|
||||
$snapshot = json_decode(file_get_contents(base_path('outputs/irpc-noncivil-20261114/'.$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']);
|
||||
$book = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$snapshot['context_opportunity']];
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertArrayHasKey('advancePeriod', $book['result']['model']);
|
||||
$this->assertSame($book['history'][0]['model']['arithmeticBalance'], $book['result']['model']['arithmeticBalance']);
|
||||
$this->assertSame($book['pecObligation'], $book['result']['model']['input']['pecObligation']);
|
||||
$this->assertSame($book['ppcObligation'], $book['result']['model']['input']['ppcObligation']);
|
||||
$this->assertSame('2026', $book['ppcObligation']['year']);
|
||||
$this->assertSame($book['advancePeriodDeclaration'], $book['result']['model']['input']['advancePeriodDeclaration']);
|
||||
$this->assertSame('SYNTHETIC effective activity2020', $book['pecObligation']['activityReference']);
|
||||
file_put_contents(base_path('outputs/irpc-noncivil-20261114/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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 IrpcPecLastAmountDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_pec_obligation_and_calendar_survive_native_draft_without_new_paid_deductions(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('investmoz_demography_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$actor = User::factory()->create();
|
||||
$this->actingAs($actor);
|
||||
$id = null;
|
||||
$etag = null;
|
||||
foreach (['documented' => 138, 'missing' => 138, 'positive' => 138, 'excess' => 138] as $name => $balance) {
|
||||
$snapshot = json_decode(file_get_contents(base_path('outputs/irpc-pec-last-amount-20261113/'.$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']);
|
||||
$book = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$snapshot['context_opportunity']];
|
||||
$this->assertCount(1, $book['history']);
|
||||
$this->assertSame(['numerator' => '138', 'denominator' => '1'], $book['history'][0]['model']['arithmeticBalance']);
|
||||
$this->assertSame($balance === null ? null : ['numerator' => (string) $balance, 'denominator' => '1'], $book['result']['model']['arithmeticBalance']);
|
||||
$this->assertSame($book['pecObligation'], $book['result']['model']['input']['pecObligation']);
|
||||
$this->assertSame('42500.25', $book['pecObligation']['lastAmount']['amount']);
|
||||
$this->assertSame('2024', $book['pecObligation']['lastAmount']['year']);
|
||||
$this->assertSame('SYNTHETIC effective activity'.($name === 'start' ? '2026' : '2020'), $book['pecObligation']['activityReference']);
|
||||
file_put_contents(base_path('outputs/irpc-pec-last-amount-20261113/recovered-'.$name.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user