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

60 lines
3.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Services\FundingProgrammes;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
/** Uses unchanged documentary institutions in the explicitly guarded QA fixture. */
final class FundingLocalPresenceAcceptanceTest extends TestCase
{
use DatabaseTransactions;
private array $fixture;
protected function setUp(): void
{
parent::setUp();
$this->withoutVite();
$this->assertSame('continuity_20261120_test', DB::connection()->getDatabaseName());
$this->fixture = json_decode(file_get_contents(base_path('outputs/funding-b03-b06-20261120/fixture.json')), true, 512, JSON_THROW_ON_ERROR);
$this->assertSame($this->fixture['source_sha256'], hash_file('sha256', database_path('data/funding-institutions-nov2026.json')));
}
private function ids(string $province, string $mode, string $certainty = 'include_unknown'): array
{
return app(FundingProgrammes::class)->catalogueQuery(['territory' => $this->fixture['provinces'][$province], 'location_mode' => $mode, 'kind' => 'institution', 'need' => 'investment', 'certainty' => $certainty])->pluck('p.id')->all();
}
public function test_national_financing_is_not_a_physical_branch_and_unknowns_are_not_confirmed(): void
{
$moza = $this->fixture['records']['moza']['id'];
$microbank = $this->fixture['records']['ac-microbanco']['id'];
$this->assertContains($moza, $this->ids('Niassa', 'coverage'));
$this->assertNotContains($moza, $this->ids('Niassa', 'physical'));
$this->assertContains($moza, $this->ids('Maputo Cidade', 'physical'));
$this->assertContains($this->fixture['records']['bci']['id'], $this->ids('Maputo Cidade', 'physical', 'documented'));
$this->assertNotContains($microbank, $this->ids('Gaza', 'physical', 'documented'));
$this->assertContains($microbank, $this->ids('Gaza', 'physical'));
}
public function test_empty_local_result_does_not_fall_back_to_the_national_catalogue(): void
{
$district = DB::table('geo_locations')->where('parent_id', $this->fixture['provinces']['Niassa'])->where('location_type', 'district')->firstOrFail();
$filters = ['territory' => $district->id, 'kind' => 'institution', 'need' => 'investment', 'location_mode' => 'physical', 'certainty' => 'documented'];
$this->get('/fundos?'.http_build_query($filters))->assertOk()
->assertInertia(fn ($page) => $page->component('funding/index')->has('items.data', 0)->where('filters.territory', $district->id)->where('filters.location_mode', 'physical')->etc());
}
public function test_each_documentary_institution_selection_opens_its_own_record(): void
{
foreach ($this->fixture['records'] as $key => $record) {
$this->get('/fundos/'.$record['id'].'?'.http_build_query(['location_mode' => 'physical', 'territory' => $this->fixture['provinces']['Maputo Cidade'], 'need' => 'investment']))->assertOk()
->assertInertia(fn ($page) => $page->component('funding/show')->where('record.id', $record['id'])->where('record.payload.title', $record['title'])->where('record.payload.institution_key', $key)->where('selection.location_mode', 'physical')->etc());
}
$this->get('/fundos/00000000-0000-4000-8000-000000000000')->assertNotFound();
}
}