81 lines
5.4 KiB
PHP
81 lines
5.4 KiB
PHP
<?php
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Opportunity;
|
|
use App\Services\InvestmentCatalogue;
|
|
use App\Services\InvestmentGeography;
|
|
use App\Services\CorridorAgribusinessOpportunities;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
final class CatalogueProvinceCoverageTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
private const PROVINCE = 'bfde2651-2b46-5d9c-a500-733fa55a8c5c';
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();\Tests\Support\ProactiveInvestmentFixture::guard();$this->withoutVite();
|
|
}
|
|
|
|
public function test_accepted_maputo_source_is_found_in_both_approved_provinces_without_becoming_a_district_site(): void
|
|
{
|
|
$c=app(InvestmentCatalogue::class);
|
|
$expected=Opportunity::published()->where('workflow_context->corridor_agribusiness->source_sha256',CorridorAgribusinessOpportunities::SOURCE_HASH)
|
|
->where('workflow_context->corridor_agribusiness->corridor','Corredor de Maputo')->pluck('id')->all();
|
|
$this->assertCount(5,$expected);
|
|
foreach([self::PROVINCE,'4aa31470-997e-5c63-8fe0-ff2f62586f56']as$province){
|
|
foreach(['all','context']as$basis){
|
|
$ids=$c->query(['sector'=>'agronegocio','province_id'=>$province,'territory_basis'=>$basis])->pluck('id')->all();
|
|
foreach($expected as$id)$this->assertContains($id,$ids);
|
|
}
|
|
}
|
|
foreach($expected as$id)$this->assertNotContains($id,$c->query(['province_id'=>self::PROVINCE,'territory_basis'=>'direct'])->pluck('id')->all());
|
|
$district=app(InvestmentGeography::class)->publicReferences()->where('parent_id',self::PROVINCE)->where('location_type','district')->first();
|
|
$this->assertNotNull($district);
|
|
foreach($expected as$id)$this->assertNotContains($id,$c->query(['province_id'=>self::PROVINCE,'district_id'=>$district->id])->pluck('id')->all());
|
|
$label=$c->presentLocation(Opportunity::findOrFail($expected[0]))->territorial_summary;
|
|
$this->assertStringContainsString('contexto provincial do corredor',$label);
|
|
$this->assertStringContainsString('distrito e posto administrativo não indicados',$label);
|
|
foreach($expected as$id)$this->assertContains($id,$c->query(['geo_location_id'=>self::PROVINCE])->pluck('id')->all());
|
|
$this->assertSame([],array_intersect($expected,$c->query(['province_id'=>'059b02ca-7095-577a-8705-4d4c46896747'])->pluck('id')->all()));
|
|
}
|
|
|
|
public function test_province_includes_its_descendants_with_full_location_and_excludes_private_and_other_provinces(): void
|
|
{
|
|
$geo=app(InvestmentGeography::class);$c=app(InvestmentCatalogue::class);
|
|
$district=$geo->publicReferences()->where('parent_id',self::PROVINCE)->where('location_type','district')->first();
|
|
$post=$geo->publicReferences()->where('parent_id',$district->id)->where('location_type','admin_post')->first();
|
|
$this->assertNotNull($post);
|
|
$make=fn($territory,$status='published')=>Opportunity::create(['sector_id'=>1,'reference'=>'SYNTHETIC-QA-'.Str::uuid(),'slug'=>'synthetic-'.Str::uuid(),'title'=>'SYNTHETIC QA province coverage','status'=>$status,'published_at'=>now()->subMinute(),'primary_territory_id'=>$territory,'geography_scope'=>'specific']);
|
|
$record=$make($post->id);$private=$make($post->id,'draft');$other=$make('059b02ca-7095-577a-8705-4d4c46896747');
|
|
$ids=$c->query(['province_id'=>self::PROVINCE,'sector'=>'agronegocio'])->pluck('id')->all();
|
|
$this->assertContains($record->id,$ids);$this->assertNotContains($private->id,$ids);$this->assertNotContains($other->id,$ids);
|
|
$label=$c->presentLocation($record)->territorial_summary;
|
|
foreach(['Maputo Província',$district->name,$post->name]as$name)$this->assertStringContainsString($name,$label);
|
|
}
|
|
|
|
public function test_actual_territory_and_publication_decisions_override_old_corridor_context(): void
|
|
{
|
|
$c=app(InvestmentCatalogue::class);
|
|
$record=Opportunity::published()->where('workflow_context->corridor_agribusiness->corridor','Corredor de Maputo')->firstOrFail();
|
|
$record->primary_territory_id='059b02ca-7095-577a-8705-4d4c46896747';$record->save();
|
|
$this->assertNotContains($record->id,$c->query(['province_id'=>self::PROVINCE])->pluck('id')->all());
|
|
$record->primary_territory_id=null;$record->status='draft';$record->save();
|
|
$this->assertNotContains($record->id,$c->query(['province_id'=>self::PROVINCE])->pluck('id')->all());
|
|
}
|
|
|
|
public function test_public_search_and_corridor_view_agree_without_inventing_map_coordinates(): void
|
|
{
|
|
$filters=['province_id'=>self::PROVINCE,'sector'=>'agronegocio'];
|
|
$response=$this->getJson('/api/v1/investment/search?'.http_build_query($filters))->assertOk()->assertJsonPath('total',5);
|
|
foreach($response->json('data')as$row)$this->assertStringContainsString('contexto provincial do corredor',$row['territorial_summary']);
|
|
$groups=app(\App\Services\OpportunityCorridorExplorer::class)->groups($filters);
|
|
$this->assertCount(1,$groups);$this->assertSame(5,$groups[0]['count']);
|
|
foreach($groups[0]['opportunities']as$row){$this->assertContains('Maputo Província',$row['provinces']);$this->assertNull($row['district']);}
|
|
$map=app(InvestmentCatalogue::class)->map($filters);
|
|
$this->assertCount(5,$map['unlocated']);$this->assertSame([],$map['features']);
|
|
}
|
|
}
|