Files
Investidor-V2/tests/Feature/CatalogueSelectorReferencesTest.php
T

94 lines
5.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Services\InvestmentCatalogue;
use App\Services\InvestmentZones;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Tests\TestCase;
class CatalogueSelectorReferencesTest extends TestCase
{
use DatabaseTransactions;
protected function setUp(): void
{
parent::setUp();
$db = DB::selectOne('select current_database() as name, inet_server_port() as port');
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
$this->assertSame(55441, (int) $db->port);
$this->withoutVite();
}
public function test_public_parks_remain_selectable_with_zero_results_without_exposing_private_or_other_territories(): void
{
$province = '059b02ca-7095-577a-8705-4d4c46896747';
$template = app(InvestmentZones::class)->visible()->firstOrFail();
$ids = [];
foreach (['public', 'private', 'other'] as $case) {
$zone = $template->replicate();
$zone->id = (string) Str::uuid();
$zone->code = 'SINT-SELECTOR-'.Str::random(12);
$zone->name = 'SINTÉTICO QA '.$case;
$zone->category = 'industrial_park';
$zone->primary_territory_id = $case === 'other' ? '9e42dac8-fd9b-523f-bf59-71a7d3aa0fb8' : $province;
$zone->publication_status = $case === 'private' ? 'draft' : 'published';
$zone->source_evidence = [['source_type' => 'government', 'url' => 'https://example.test/qa-only', 'supports' => 'Synthetic QA fixture, not a legal source']];
$zone->save();
$ids[$case] = $zone->id;
}
$scope = ['province_id' => $province, 'park_id' => $ids['public'], 'q' => 'no-matching-opportunity-'.Str::uuid()];
$this->assertSame(0, app(InvestmentCatalogue::class)->query($scope)->count());
$response = $this->getJson('/api/v1/investment/references?'.http_build_query($scope))->assertOk();
$available = array_column($response->json('zones'), 'id');
$this->assertContains($ids['public'], $available);
$this->assertNotContains($ids['private'], $available);
$this->assertNotContains($ids['other'], $available);
$this->assertContains($ids['other'], array_column($this->getJson('/api/v1/investment/references')->assertOk()->json('zones'), 'id'));
$this->get('/zonas/'.$ids['public'])->assertOk();
$this->get('/zonas/'.$ids['private'])->assertNotFound();
}
public function test_activity_catalogue_does_not_disappear_when_opportunity_search_has_no_matches(): void
{
$catalogue = app(InvestmentCatalogue::class);
$global = collect($catalogue->references()['classification']['targets']['activity'])->pluck('id')->all();
$this->assertNotEmpty($global);
foreach (['059b02ca-7095-577a-8705-4d4c46896747', '9e42dac8-fd9b-523f-bf59-71a7d3aa0fb8'] as $province) {
$scope = ['province_id' => $province, 'q' => 'no-matching-opportunity-'.Str::uuid(), 'sector' => 'tourism'];
$this->assertSame(0, $catalogue->query($scope)->count());
$this->assertSame($global, collect($catalogue->references(false, $scope)['classification']['targets']['activity'])->pluck('id')->all());
}
}
public function test_public_master_structures_and_chain_are_available_without_opportunities_or_published_dossiers(): void
{
$province = '059b02ca-7095-577a-8705-4d4c46896747';
$clusters = [];
foreach (['public', 'internal'] as $visibility) {
$id = (string) Str::uuid();
DB::table('economic_clusters')->insert(['id' => $id, 'code' => 'SINT-'.Str::random(12), 'name' => 'SINTÉTICO QA cluster',
'sector' => 'QA', 'status' => 'active', 'data_classification' => $visibility, 'primary_territory_id' => $province]);
$clusters[$visibility] = $id;
}
$corridor = (string) Str::uuid();
DB::table('development_corridors')->insert(['id' => $corridor, 'code' => 'SINT-'.Str::random(12), 'name' => 'SINTÉTICO QA corredor',
'status' => 'active', 'data_classification' => 'public', 'primary_territory_id' => $province]);
$project = \App\Models\Project::factory()->create(['data_classification' => 'public', 'primary_territory_id' => $province]);
$chain = (string) Str::uuid();
DB::table('value_chains')->insert(['id' => $chain, 'cluster_id' => $clusters['public'], 'code' => 'SINT-'.Str::random(12),
'name' => 'SINTÉTICO QA cadeia', 'stage' => 'production', 'data_classification' => 'public']);
$refs = app(InvestmentCatalogue::class)->references(false, ['province_id' => $province, 'q' => 'no-matching-opportunity']);
$this->assertContains($clusters['public'], $refs['clusters']->pluck('id')->all());
$this->assertNotContains($clusters['internal'], $refs['clusters']->pluck('id')->all());
$this->assertContains($corridor, $refs['corridors']->pluck('id')->all());
$this->assertContains($project->id, $refs['projects']->pluck('id')->all());
$this->assertContains($chain, collect($refs['classification']['targets']['chain'])->pluck('id')->all());
$other = app(InvestmentCatalogue::class)->references(false, ['province_id' => '9e42dac8-fd9b-523f-bf59-71a7d3aa0fb8']);
$this->assertNotContains($clusters['public'], $other['clusters']->pluck('id')->all());
$this->assertNotContains($chain, collect($other['classification']['targets']['chain'])->pluck('id')->all());
}
}