Files
Investidor-V2/tests/Feature/PiiIntegratedProjectsTest.php
T
Claude 87017986e1 Carteira 4.3: projectos integrados do PII como projectos planeados internos, por confirmar
Decisões do proprietário de 05/12: duplicados separados e referenciados, moeda do A10
indefinida, ANC fora do PII excluídos, registos internos e não publicados. O comando
portfolio:load-pii-integrated simula por omissão e só cria com --execute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
2026-12-05 12:03:47 +02:00

60 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Feature;
use App\Services\PiiIntegratedProjects;
use Database\Seeders\InvestmentPortfolioSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
final class PiiIntegratedProjectsTest extends TestCase
{
use RefreshDatabase;
public function test_integrated_projects_are_created_internal_planned_and_unconfirmed_without_inventing_values(): void
{
$this->seed(InvestmentPortfolioSeeder::class);
$load = app(PiiIntegratedProjects::class);
$before = DB::table('projects')->count();
$dry = $load->run(false);
$this->assertCount(161, $dry['create']);
$this->assertSame($before, DB::table('projects')->count());
$result = $load->run(true);
$this->assertCount(161, $result['create']);
$this->assertSame([], $result['collisions']);
$created = DB::table('projects')->where('source_system', PiiIntegratedProjects::SOURCE_SYSTEM);
$this->assertSame(161, (clone $created)->count());
$this->assertSame(0, (clone $created)->where(fn ($q) => $q->where('status', '!=', 'planned')->orWhere('data_classification', '!=', 'internal'))->count());
$this->assertSame(0, (clone $created)->whereNotNull('start_date')->count());
$this->assertSame(0, DB::table('investment_dossiers')->whereIn('project_id', (clone $created)->select('id'))->count());
$this->assertSame(0, DB::table('opportunities')->count());
// A10 table has a «USD/MZN» header: no currency is chosen, the literal is kept.
$mphanda = (clone $created)->where('code', 'A10-C01')->first();
$this->assertNull($mphanda->budget_amount);
$this->assertSame('800.000.000', json_decode($mphanda->metadata, true)['pii']['cost_literal']);
$this->assertSame('Cahora Bassa Norte (HCB)', $mphanda->name);
// Both container terminals stay, each pointing at the other.
foreach (['A07-C02', 'A08-C02'] as $code) {
$meta = json_decode((clone $created)->where('code', $code)->value('metadata'), true);
$this->assertSame('por_confirmar', $meta['confirmation_status']);
$this->assertCount(1, $meta['possible_duplicate_of']);
$this->assertStringContainsString('Terminal de Contentores – Porto de Nacala', $meta['possible_duplicate_of'][0]);
}
$this->assertSame('16100000.00', (clone $created)->where('code', 'A03-C01')->value('budget_amount'));
$links = DB::table('complementary_project_links')->where('source_system', PiiIntegratedProjects::SOURCE_SYSTEM);
$this->assertSame($result['links'], (clone $links)->count());
$this->assertSame(161, $result['links'] + count($result['without_relation']));
$this->assertSame(0, (clone $links)->where('data_classification', '!=', 'internal')->count());
$again = $load->run(true);
$this->assertSame([[], 161], [$again['create'], $again['existing']]);
$this->assertSame(161, (clone $created)->count());
}
}