Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
51 lines
2.9 KiB
PHP
51 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\InvestmentDossier;
|
|
use App\Models\Opportunity;
|
|
use App\Models\Sector;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
final class PortfolioNearbyOpportunitiesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_record_without_links_lists_same_province_and_sector_opportunities_as_not_linked(): void
|
|
{
|
|
$this->withoutVite();
|
|
$ids = [];
|
|
$parent = null;
|
|
foreach (['country' => 'SYNTHETIC Moçambique', 'province' => 'SYNTHETIC Inhambane', 'district' => 'SYNTHETIC Vilankulo'] as $type => $name) {
|
|
$id = (string) Str::uuid();
|
|
DB::table('geo_locations')->insert(['id' => $id, 'parent_id' => $parent, 'name' => $name, 'code' => $id, 'location_type' => $type,
|
|
'source_system' => 'cartografia-workbook', 'data_classification' => 'public',
|
|
'external_id' => '964a187ad32ea553b9e112cd159caa90b900050c42b7329594a75bcd798a96ff:QA:'.$id]);
|
|
$ids[$type] = $parent = $id;
|
|
}
|
|
$project = (string) Str::uuid();
|
|
DB::table('projects')->insert(['id' => $project, 'code' => 'SYNTHETIC-A13', 'name' => 'Projecto fictício', 'status' => 'draft',
|
|
'primary_territory_id' => $ids['district'], 'metadata' => '{}', 'data_classification' => 'public']);
|
|
$dossier = InvestmentDossier::create(['project_id' => $project, 'title' => 'SYNTHETIC Região de Turismo', 'source' => 'Synthetic fixture only',
|
|
'content' => ['sector' => 'Turismo / Serviços'], 'publication_status' => 'published', 'published_at' => now()->subMinute(),
|
|
'data_classification' => 'public', 'approval_basis' => 'document_owner', 'approval_evidence' => 'Synthetic QA fixture only']);
|
|
$make = fn (string $sector, string $title) => Opportunity::create(['sector_id' => Sector::firstOrCreate(['slug' => Str::slug($sector)], ['name' => $sector, 'is_active' => true])->id,
|
|
'reference' => 'SYNTHETIC-'.Str::uuid(), 'slug' => 'synthetic-'.Str::uuid(), 'title' => $title, 'status' => 'published',
|
|
'published_at' => now()->subMinute(), 'primary_territory_id' => $ids['district'], 'geography_scope' => 'specific']);
|
|
$tourism = $make('Turismo', 'SYNTHETIC hotel');
|
|
$make('Economia Azul', 'SYNTHETIC conservação');
|
|
|
|
$nearby = fn () => $this->get('/carteira/'.$dossier->id)->assertOk()->viewData('page')['props']['nearby'];
|
|
$result = $nearby();
|
|
$this->assertSame(['SYNTHETIC Inhambane'], $result['provinces']);
|
|
$this->assertSame([$tourism->id], array_column($result['items'], 'id'));
|
|
$this->assertSame(0, DB::table('opportunity_projects')->count());
|
|
|
|
DB::table('opportunity_projects')->insert(['opportunity_id' => $tourism->id, 'project_id' => $project]);
|
|
$this->assertNull($nearby());
|
|
}
|
|
}
|