Consolida rastreabilidade territorial e plano autenticado V2
This commit is contained in:
@@ -12,6 +12,7 @@ use App\Services\InvestmentCatalogue;
|
||||
use App\Services\InvestmentRelations;
|
||||
use App\Services\InvestmentRelationshipRepair;
|
||||
use App\Services\InvestmentTerritorialValidation;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -104,7 +105,7 @@ class InvestmentRelationshipTest extends TestCase
|
||||
$this->get('/carteira/'.$f['dossier']->id)->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_ambiguous_multiple_sites_do_not_choose_an_arbitrary_opportunity_marker(): void
|
||||
public function test_multiple_documented_sites_are_shown_separately_without_choosing_one(): void
|
||||
{
|
||||
$f = $this->fixture();
|
||||
$id = (string) Str::uuid();
|
||||
@@ -112,11 +113,59 @@ class InvestmentRelationshipTest extends TestCase
|
||||
DB::table('project_locations')->insert(['id' => (string) Str::uuid(), 'project_id' => $f['project']->id, 'geo_location_id' => $id, 'role' => 'secondary', 'data_classification' => 'public']);
|
||||
DB::table('geo_geometries')->insert(['id' => (string) Str::uuid(), 'geo_location_id' => $id, 'geometry_type' => 'point', 'data_classification' => 'public', 'geom' => DB::raw('ST_SetSRID(ST_MakePoint(32.6,-25.8),4326)')]);
|
||||
$map = app(InvestmentCatalogue::class)->map([]);
|
||||
$this->assertSame(0, $map['georeferenced_count']);
|
||||
$this->assertCount(1, $map['unlocated']);
|
||||
$this->assertSame(1, $map['georeferenced_count']);
|
||||
$this->assertCount(0, $map['unlocated']);
|
||||
$this->assertCount(2, $map['features']);
|
||||
$this->assertSame(2, $map['marker_count']);
|
||||
$this->assertCount(2, app(InvestmentRelations::class)->projectLocations($f['project']->id));
|
||||
}
|
||||
|
||||
public function test_direct_context_impact_and_missing_geography_remain_distinct(): void
|
||||
{
|
||||
$f = $this->fixture();
|
||||
$catalogue = app(InvestmentCatalogue::class);
|
||||
$this->assertEmpty($catalogue->context($f['opportunity']->id)['opportunity_locations']);
|
||||
$this->assertSame([$f['opportunity']->id], $catalogue->query(['territory_basis' => 'context'])->pluck('id')->all());
|
||||
$this->assertSame([], $catalogue->query(['territory_basis' => 'direct'])->pluck('id')->all());
|
||||
DB::table('opportunity_locations')->insert(['opportunity_id' => $f['opportunity']->id, 'geo_location_id' => $f['ids']['district']]);
|
||||
$location = $catalogue->context($f['opportunity']->id)['opportunity_locations'][0];
|
||||
$this->assertSame('opportunity', $location['role']);
|
||||
$this->assertSame([$f['opportunity']->id], $catalogue->query(['q' => 'QA district'])->pluck('id')->all());
|
||||
$this->assertNull($location['source_reference']);
|
||||
$this->assertEmpty($location['coordinates']);
|
||||
$this->assertSame([], $catalogue->query(['territory_basis' => 'context'])->pluck('id')->all());
|
||||
$this->assertSame([$f['opportunity']->id], $catalogue->query(['territory_basis' => 'direct', 'geo_location_id' => $f['ids']['district']])->pluck('id')->all());
|
||||
$this->assertSame([], $catalogue->query(['territory_basis' => 'direct', 'geo_location_id' => $f['ids']['site']])->pluck('id')->all());
|
||||
DB::table('project_locations')->update(['role' => 'impact']);
|
||||
$this->assertSame('impact', $catalogue->context($f['opportunity']->id)['projects'][0]->geography['locations'][0]['role']);
|
||||
$this->assertSame(0, $catalogue->map([])['georeferenced_count']);
|
||||
DB::table('opportunity_locations')->delete();
|
||||
DB::table('opportunity_projects')->delete();
|
||||
$this->assertEmpty($catalogue->context($f['opportunity']->id)['opportunity_locations']);
|
||||
$this->assertSame(1, $catalogue->query([])->count());
|
||||
$this->assertCount(1, $catalogue->map([])['unlocated']);
|
||||
}
|
||||
|
||||
public function test_invalid_coordinates_are_rejected_and_polygon_provenance_is_preserved(): void
|
||||
{
|
||||
$f = $this->fixture();
|
||||
DB::table('opportunity_locations')->insert(['opportunity_id' => $f['opportunity']->id, 'geo_location_id' => $f['ids']['site']]);
|
||||
DB::table('geo_geometries')->insert(['id' => (string) Str::uuid(), 'geo_location_id' => $f['ids']['site'], 'geometry_type' => 'polygon', 'data_classification' => 'public',
|
||||
'geom' => DB::raw("ST_GeomFromText('POLYGON((32 -26,33 -26,33 -25,32 -25,32 -26))',4326)"), 'source_system' => 'QA boundary', 'properties' => json_encode(['source_date' => '2026-10-08'])]);
|
||||
$context = app(InvestmentCatalogue::class)->context($f['opportunity']->id);
|
||||
$this->assertSame('2026-10-08', $context['opportunity_locations'][0]['boundaries'][0]['source_date']);
|
||||
$this->assertSame('opportunity_site', app(InvestmentCatalogue::class)->map([])['features'][0]['properties']['location_basis']);
|
||||
$this->assertCount(1, app(InvestmentCatalogue::class)->map([])['areas']);
|
||||
try {
|
||||
DB::transaction(fn () => DB::table('geo_geometries')->where('geo_location_id', $f['ids']['site'])->where('geometry_type', 'point')->update(['geom' => DB::raw('ST_SetSRID(ST_MakePoint(32.7,95),4326)')]));
|
||||
$this->fail('Invalid coordinates must be rejected by the existing database guard.');
|
||||
} catch (QueryException $error) {
|
||||
$this->assertSame('23514', $error->getCode());
|
||||
}
|
||||
$this->assertSame(1, app(InvestmentCatalogue::class)->map([])['georeferenced_count']);
|
||||
$this->assertCount(1, app(InvestmentCatalogue::class)->context($f['opportunity']->id)['opportunity_locations'][0]['coordinates']);
|
||||
}
|
||||
|
||||
public function test_repair_requires_authenticated_management_is_transactional_and_replays_without_duplicates(): void
|
||||
{
|
||||
$f = $this->fixture();
|
||||
|
||||
Reference in New Issue
Block a user