test(catalogue): verify provincial coverage nationally and across sectors
This commit is contained in:
@@ -77,4 +77,50 @@ final class CatalogueProvinceCoverageTest extends TestCase
|
||||
$map=app(InvestmentCatalogue::class)->map($filters);
|
||||
$this->assertCount(5,$map['unlocated']);$this->assertSame([],$map['features']);
|
||||
}
|
||||
|
||||
public function test_all_approved_corridors_are_found_in_their_provinces_and_not_in_unrelated_provinces(): void
|
||||
{
|
||||
$catalogue=app(InvestmentCatalogue::class);
|
||||
$provinces=app(InvestmentGeography::class)->publicReferences()->where('location_type','province')->get();
|
||||
$this->assertCount(11,$provinces);
|
||||
foreach(config('investment_corridors')as$entry){
|
||||
$records=Opportunity::published()->whereNull('primary_territory_id')
|
||||
->where('workflow_context->corridor_agribusiness->source_sha256',CorridorAgribusinessOpportunities::SOURCE_HASH)
|
||||
->where('workflow_context->corridor_agribusiness->corridor',$entry['name'])->pluck('id')->all();
|
||||
$this->assertNotEmpty($records,$entry['name']);
|
||||
foreach($provinces as$province){
|
||||
$ids=$catalogue->query(['province_id'=>$province->id,'sector'=>'agronegocio'])->pluck('id')->all();
|
||||
foreach($records as$id){
|
||||
if(in_array($province->source_code,$entry['provinces'],true))$this->assertContains($id,$ids);
|
||||
else $this->assertNotContains($id,$ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_descendant_coverage_is_national_and_shared_by_sectors_and_location_entry_points(): void
|
||||
{
|
||||
$geo=app(InvestmentGeography::class);$catalogue=app(InvestmentCatalogue::class);
|
||||
$provinces=$geo->publicReferences()->where('location_type','province')->get();
|
||||
$sectors=DB::table('sectors')->where('is_active',true)->whereNotNull('published_at')->whereNull('deleted_at')->orderBy('id')->limit(2)->get();
|
||||
$this->assertCount(2,$sectors);
|
||||
foreach($provinces as$province){
|
||||
$district=$geo->publicReferences()->where('parent_id',$province->id)->where('location_type','district')->first();
|
||||
$this->assertNotNull($district,$province->name);
|
||||
$post=$geo->publicReferences()->where('parent_id',$district->id)->where('location_type','admin_post')->first();
|
||||
$leaf=$post?:$district;
|
||||
foreach($sectors as$sector){
|
||||
$record=Opportunity::create(['sector_id'=>$sector->id,'reference'=>'SYNTHETIC-QA-'.Str::uuid(),'slug'=>'synthetic-'.Str::uuid(),
|
||||
'title'=>'SYNTHETIC QA national coverage','status'=>'published','published_at'=>now()->subMinute(),'primary_territory_id'=>$leaf->id,'geography_scope'=>'specific']);
|
||||
foreach([['province_id'=>$province->id],['geo_location_id'=>$province->id],['province_id'=>$province->id,'district_id'=>$district->id]]as$entry){
|
||||
$this->assertContains($record->id,$catalogue->query([...$entry,'sector'=>$sector->slug])->pluck('id')->all());
|
||||
}
|
||||
$other=$sectors->firstWhere('id','!=',$sector->id);
|
||||
$this->assertNotContains($record->id,$catalogue->query(['province_id'=>$province->id,'sector'=>$other->slug])->pluck('id')->all());
|
||||
$label=$catalogue->presentLocation($record)->territorial_summary;
|
||||
$this->assertStringContainsString($province->name,$label);$this->assertStringContainsString($district->name,$label);
|
||||
if($post)$this->assertStringContainsString($post->name,$label);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user