Junta os 15 âncoras e os 161 projectos integrados do relatório final do PII 2026–2030, as referências provinciais da MozParks e o inventário ANC (não oficial) num ficheiro de staging rastreável, e o comando portfolio:simulate-pii-import compara-os com a base: correspondências, candidatas oportunidade↔projecto, duplicações, localizações, custos ambíguos, relações pendentes e campos ausentes. Não grava nada. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
78 lines
5.0 KiB
PHP
78 lines
5.0 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use App\Models\Opportunity;
|
||
use App\Models\Sector;
|
||
use App\Services\PiiPortfolioImportSimulation;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Str;
|
||
use Tests\TestCase;
|
||
|
||
class PiiPortfolioImportSimulationTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
public function test_staging_keeps_every_pii_row_traceable_and_never_open(): void
|
||
{
|
||
$data = app(PiiPortfolioImportSimulation::class)->data();
|
||
$this->assertSame('review_only_not_importable', $data['status']);
|
||
$this->assertSame('bcbf8ec976100cc5e978aef54050c3e3e9d959b0d361fa80a788528a8e5049a6', $data['source']['sha256']);
|
||
$this->assertCount(15, $data['anchors']);
|
||
$this->assertCount(176, $data['integrated']);
|
||
$this->assertCount(161, array_filter($data['integrated'], fn ($r) => $r['role'] === 'complementary'));
|
||
$refs = array_map(fn ($r) => $r['source_table_index'].'/'.$r['source_table_row'], $data['integrated']);
|
||
$this->assertSame(count($refs), count(array_unique($refs)));
|
||
// Table 21 is A14 although its caption says A11: the anchor comes from the table order.
|
||
$this->assertSame(['A14'], array_values(array_unique(array_column(array_filter($data['integrated'], fn ($r) => $r['source_table_index'] === 24), 'anchor'))));
|
||
$this->assertCount(22, $data['secondary_inventory']['records']);
|
||
}
|
||
|
||
public function test_costs_are_read_literally_and_doubts_are_flagged(): void
|
||
{
|
||
$s = app(PiiPortfolioImportSimulation::class);
|
||
$this->assertSame(16100000.0, $s->cost('16.100.000', 'Custo Total (USD)')['value']);
|
||
$this->assertSame(550000000.0, $s->cost('550,000,000', 'Custo (USD)')['value']);
|
||
$this->assertSame(120000000.0, $s->cost('120 000 000', 'Custo (USD)')['value']);
|
||
$this->assertSame(['espaço dentro do número'], $s->cost('1.000.000. 000', 'Custo (USD)')['flags']);
|
||
$this->assertSame(67558964.79, $s->cost('67.558.964,79', 'Custo (USD)')['value']);
|
||
$this->assertNull($s->cost('Carece de estudos', 'Custo (USD)')['value']);
|
||
$this->assertNull($s->cost('800.000.000', 'Custo (USD/ MZN)')['currency']);
|
||
$this->assertSame(99200000.0, $s->cost('99.200.000 / /', 'Custo (USD)')['value']);
|
||
$this->assertNull($s->cost('1 / 2', 'Custo (USD)')['value']);
|
||
$this->assertContains('ordem de grandeza a confirmar', $s->cost('30,000,000,000', 'Custo (USD)')['flags']);
|
||
}
|
||
|
||
public function test_simulation_proposes_candidates_without_writing_anything(): void
|
||
{
|
||
foreach (['NACALA-PORTO', 'NACALA-VELHA', 'Cabo Delgado'] as $name) {
|
||
DB::table('geo_locations')->insert(['id' => $id = (string) Str::uuid(), 'code' => $id, 'name' => $name, 'location_type' => 'district', 'parent_id' => null]);
|
||
}
|
||
$sector = Sector::create(['name' => 'Energia sintética', 'slug' => 'energia-sintetica', 'is_active' => true]);
|
||
$opportunity = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'SYNTHETIC-PII', 'slug' => 'synthetic-pii',
|
||
'title' => 'Fornecimento de agregados para Mphanda Nkuwa', 'status' => 'published', 'published_at' => now()->subMinute()]);
|
||
$before = [DB::table('opportunity_projects')->count(), DB::table('projects')->count(), DB::table('complementary_project_links')->count()];
|
||
|
||
$result = app(PiiPortfolioImportSimulation::class)->run();
|
||
|
||
$this->assertSame($before, [DB::table('opportunity_projects')->count(), DB::table('projects')->count(), DB::table('complementary_project_links')->count()]);
|
||
$this->assertSame('not_in_portal', $result['anchors'][0]['state']);
|
||
$candidate = collect($result['opportunity_candidates'])->firstWhere('opportunity.ref', 'SYNTHETIC-PII');
|
||
$this->assertNotNull($candidate);
|
||
$this->assertStringContainsString('Mphanda Nkuwa', $candidate['source']);
|
||
$this->assertSame(['mphanda', 'nkuwa'], array_values(array_intersect(['mphanda', 'nkuwa'], $candidate['opportunity']['shared'])));
|
||
$nacala = collect($result['rows'])->firstWhere('title', 'Estrada de Acesso ao Porto de Nacala');
|
||
$this->assertSame('parcial', $nacala['location']['state']);
|
||
$this->assertStringContainsString('NACALA-PORTO | NACALA-VELHA', $nacala['location']['ambiguous'][0]);
|
||
$containers = collect($result['duplicates'])->filter(fn ($d) => $d['a']['title'] === 'Terminal de Contentores – Porto de Nacala');
|
||
$this->assertCount(1, $containers);
|
||
// Two schools in different places are not duplicates.
|
||
$this->assertFalse(collect($result['duplicates'])->contains(fn ($d) => str_contains($d['a']['title'], 'Escola Técnico-Profissional')));
|
||
$this->assertSame($opportunity->id, Opportunity::published()->sole()->id);
|
||
|
||
$this->artisan('portfolio:simulate-pii-import')->expectsOutputToContain('só leitura; nada foi gravado')
|
||
->expectsOutputToContain('SYNTHETIC-PII «Fornecimento de agregados para Mphanda Nkuwa»')->assertSuccessful();
|
||
}
|
||
}
|