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

72 lines
4.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Controllers\InvestmentPortfolioController;
use App\Models\Opportunity;
use App\Models\User;
use App\Services\CorridorAgribusinessOpportunities;
use App\Services\InvestmentCatalogue;
use App\Services\InvestmentGeography;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
/** Existing documentary records and disclosure states only; never creates opportunities. */
final class PortfolioOpportunityAcceptanceTest extends TestCase
{
use DatabaseTransactions;
protected function setUp(): void
{
parent::setUp();
$this->withoutVite();
$this->assertSame('main_reference_20261104_test', DB::connection()->getDatabaseName());
}
public function test_documentary_source_records_are_available_and_searchable_without_inventing_sites(): void
{
$entries = app(CorridorAgribusinessOpportunities::class)->entries();
$this->assertCount(34, $entries);
foreach ($entries as $entry) {
$record = Opportunity::where('management_creation_key', $entry['key'])->firstOrFail();
$this->assertTrue(Opportunity::published()->whereKey($record->id)->exists(), $entry['title']);
$this->assertTrue(app(InvestmentCatalogue::class)->query(['q' => $entry['chain']])->whereKey($record->id)->exists(), $entry['title']);
$this->assertNull($record->primary_territory_id);
$this->assertNull($record->province);
}
}
public function test_public_opportunities_are_embedded_even_without_matching_portfolio_fiches(): void
{
$record = Opportunity::published()->where('title', 'Soja — Corredor da Beira')->firstOrFail();
$this->get('/carteira?q=Soja')->assertOk()->assertInertia(fn ($page) => $page->component('portfolio/index')
->has('publishedOpportunities.data', 2)
->where('publishedOpportunities.data', fn ($items) => collect($items)->contains('id', $record->id))->etc());
$this->get('/carteira?kind=corridor&q=Beira')->assertOk()->assertInertia(fn ($page) => $page->component('portfolio/index')->has('publishedOpportunities.data', 7)->etc());
}
public function test_province_does_not_promote_unsited_opportunities_or_fiches_from_another_province(): void
{
$geography = app(InvestmentGeography::class);
$zambezia = $geography->publicReferences()->where('location_type', 'province')->where('name', 'Zambezia')->value('id');
$maputo = $geography->publicReferences()->where('location_type', 'province')->where('name', 'Maputo Província')->value('id');
$mocuba = InvestmentPortfolioController::visible()->where('title', 'Construção da Cidadela Parlamentar de Mocuba')->firstOrFail();
foreach ([[$zambezia, true], [$maputo, false]] as [$province, $expected]) {
$this->assertNotEmpty($province);
$this->get('/carteira?'.http_build_query(['province_id' => $province, 'q' => 'Mocuba']))->assertOk()->assertInertia(fn ($page) => $page->component('portfolio/index')
->where('records.data', fn ($items) => collect($items)->contains('id', $mocuba->id) === $expected)->etc());
$this->get('/carteira?'.http_build_query(['province_id' => $province, 'q' => 'Soja']))->assertOk()->assertInertia(fn ($page) => $page->component('portfolio/index')->has('publishedOpportunities.data', 0)->etc());
}
}
public function test_real_published_opportunity_reaches_normal_private_entry_without_invented_territory(): void
{
$record = Opportunity::published()->where('title', 'Soja — Corredor da Beira')->firstOrFail();
$actor = User::factory()->create(['name' => 'SINTÉTICO — verificação de percurso documental']);
$this->actingAs($actor)->get('/investimentos/iniciar?source=opportunity:'.$record->id)->assertOk()
->assertInertia(fn ($page) => $page->component('investor-path/context-start')->where('source.id', (string) $record->id)->etc());
$this->assertNull($record->fresh()->primary_territory_id);
}
}