fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+26 -23
View File
@@ -15,49 +15,52 @@ class OpportunitySearchTest extends TestCase
public function createApplication(): Application
{
$app=parent::createApplication();
if (! IsolatedQaDatabase::allowsSchemaChanges()) throw new \LogicException('Isolated QA required before test transaction');
$app = parent::createApplication();
if (! IsolatedQaDatabase::allowsSchemaChanges()) {
throw new \LogicException('Isolated QA required before test transaction');
}
return $app;
}
public function test_one_park_selector_matches_public_associations_not_proximity_or_shared_territory(): void
{
$f=OpportunitySearchFixture::create();
$q=['park_id'=>$f['zone']->id,'q'=>$f['query']];
$f = OpportunitySearchFixture::create();
$q = ['park_id' => $f['zone']->id, 'q' => $f['query']];
$this->getJson('/api/v1/investment/search?'.http_build_query($q))->assertOk()
->assertJsonPath('total',1)->assertJsonPath('data.0.id',$f['associated']->id);
$this->assertSame(1,app(InvestmentCatalogue::class)->map($q)['unlocated_count']??count(app(InvestmentCatalogue::class)->map($q)['unlocated']));
$this->getJson('/api/v1/investment/search?'.http_build_query([...$q,'currency'=>'MZN']))->assertOk()->assertJsonPath('total',0);
$this->getJson('/api/v1/investment/search?'.http_build_query(['association_type'=>'park','association_target'=>$f['zone']->id]))
->assertOk()->assertJsonPath('total',1)->assertJsonPath('data.0.id',$f['associated']->id);
->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $f['associated']->id);
$this->assertSame(1, app(InvestmentCatalogue::class)->map($q)['unlocated_count'] ?? count(app(InvestmentCatalogue::class)->map($q)['unlocated']));
$this->getJson('/api/v1/investment/search?'.http_build_query([...$q, 'currency' => 'MZN']))->assertOk()->assertJsonPath('total', 0);
$this->getJson('/api/v1/investment/search?'.http_build_query(['association_type' => 'park', 'association_target' => $f['zone']->id]))
->assertOk()->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $f['associated']->id);
}
public function test_historical_and_current_preparation_with_equal_numbers_are_not_equivalent(): void
{
$f=OpportunitySearchFixture::create();
$this->getJson('/api/v1/investment/search?'.http_build_query(['q'=>$f['query'],'preparation'=>'historical:2']))
->assertOk()->assertJsonPath('total',1)->assertJsonPath('data.0.id',$f['associated']->id);
$this->getJson('/api/v1/investment/search?'.http_build_query(['q'=>$f['query'],'preparation'=>'stage:concept']))
->assertOk()->assertJsonPath('total',1)->assertJsonPath('data.0.id',$f['nearby']->id);
$f = OpportunitySearchFixture::create();
$this->getJson('/api/v1/investment/search?'.http_build_query(['q' => $f['query'], 'preparation' => 'historical:2']))
->assertOk()->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $f['associated']->id);
$this->getJson('/api/v1/investment/search?'.http_build_query(['q' => $f['query'], 'preparation' => 'stage:concept']))
->assertOk()->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $f['nearby']->id);
}
public function test_amount_requires_currency_and_combines_with_sector_location_and_modality(): void
{
$f=OpportunitySearchFixture::create();
$f = OpportunitySearchFixture::create();
$this->getJson('/api/v1/investment/search?max_amount=500000')->assertUnprocessable()->assertJsonValidationErrors('currency');
$q=['q'=>$f['query'],'sector'=>'turismo','province_id'=>$f['province']->id,
'category'=>'investment_project','preparation'=>'historical:2','max_amount'=>'500000','currency'=>'USD'];
$this->getJson('/api/v1/investment/search?'.http_build_query($q))->assertOk()->assertJsonPath('total',1)->assertJsonPath('data.0.id',$f['associated']->id);
$this->getJson('/api/v1/investment/search?'.http_build_query([...$q,'max_amount'=>'1']))->assertOk()->assertJsonPath('total',0);
$this->getJson('/api/v1/investment/search?'.http_build_query([...$q,'category'=>'business_sale']))->assertOk()->assertJsonPath('total',0);
$q = ['q' => $f['query'], 'sector' => 'turismo', 'province_id' => $f['province']->id,
'category' => 'investment_project', 'preparation' => 'historical:2', 'max_amount' => '500000', 'currency' => 'USD'];
$this->getJson('/api/v1/investment/search?'.http_build_query($q))->assertOk()->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $f['associated']->id);
$this->getJson('/api/v1/investment/search?'.http_build_query([...$q, 'max_amount' => '1']))->assertOk()->assertJsonPath('total', 0);
$this->getJson('/api/v1/investment/search?'.http_build_query([...$q, 'category' => 'business_sale']))->assertOk()->assertJsonPath('total', 0);
}
public function test_zone_options_are_not_filtered_by_opportunity_text_or_modality(): void
{
$f=OpportunitySearchFixture::create();
$f = OpportunitySearchFixture::create();
$this->getJson('/api/v1/investment/references?q=turismo&category=investment_project')->assertOk()
->assertJsonFragment(['id'=>$f['zone']->id,'name'=>$f['zone']->name,'category'=>'industrial_park']);
$this->getJson('/api/v1/investment/search?'.http_build_query(['park_id'=>$f['zone']->id,'association_type'=>'park','association_target'=>$f['other_zone']->id]))
->assertJsonFragment(['id' => $f['zone']->id, 'name' => $f['zone']->name, 'category' => 'industrial_park']);
$this->getJson('/api/v1/investment/search?'.http_build_query(['park_id' => $f['zone']->id, 'association_type' => 'park', 'association_target' => $f['other_zone']->id]))
->assertUnprocessable()->assertJsonValidationErrors('park_id');
}