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

96 lines
5.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Services\InvestmentCatalogue;
use App\Support\IsolatedQaDatabase;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\Support\OpportunitySearchFixture;
use Tests\TestCase;
class OpportunitySearchTest extends TestCase
{
use DatabaseTransactions;
public function createApplication(): Application
{
$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']];
$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);
}
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);
}
public function test_amount_requires_currency_and_combines_with_sector_location_and_modality(): void
{
$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);
}
public function test_zone_options_are_not_filtered_by_opportunity_text_or_modality(): void
{
$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]))
->assertUnprocessable()->assertJsonValidationErrors('park_id');
}
public function test_list_map_and_export_keep_the_same_public_park_results(): void
{
$f = OpportunitySearchFixture::create();
$query = http_build_query(['q' => $f['query'], 'park_id' => $f['zone']->id]);
$this->get('/oportunidades?'.$query)->assertOk()->assertInertia(fn ($page) => $page
->component('investment/catalogue')->where('results.total', 1)
->where('results.data.0.id', $f['associated']->id));
$csv = $this->get('/api/v1/investment/export?'.$query)->assertOk()->streamedContent();
$this->assertStringContainsString($f['associated']->title, $csv);
$this->assertStringNotContainsString($f['nearby']->title, $csv);
$this->assertStringNotContainsString($f['private']->title, $csv);
}
public function test_public_catalogue_consumers_keep_their_own_result_collections(): void
{
foreach ([
'/carteira?q=SINTETICO-INEXISTENTE' => ['portfolio/index', 'records.total'],
'/zonas?q=SINTETICO-INEXISTENTE' => ['investment/zones', 'records.total'],
'/documentos?q=SINTETICO-INEXISTENTE' => ['portal/services', 'resources.total'],
'/legislacao?q=SINTETICO-INEXISTENTE' => ['portal/services', 'resources.total'],
'/educacao?q=SINTETICO-INEXISTENTE' => ['investment/catalogue', 'results.total'],
'/negocios?q=SINTETICO-INEXISTENTE' => ['investment/business-marketplace', 'results.meta.total'],
] as $url => [$component, $total]) {
$this->get($url)->assertOk()->assertInertia(fn ($page) => $page->component($component)->where($total, 0));
}
$this->get('/clusters')->assertRedirect('/carteira?kind=cluster');
$this->get('/corredores')->assertRedirect('/carteira?kind=corridor');
}
}