test(funding): demonstrate B03 B06 with documentary institutions in QA
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ const text = (tree) =>
|
||||
: '';
|
||||
|
||||
// Real page event handlers, simulated Inertia transport. Not a browser or visual acceptance.
|
||||
function harness(filters, errors = {}) {
|
||||
function harness(filters, errors = {}, items = []) {
|
||||
const memory = [];
|
||||
let cursor = 0;
|
||||
const state = (initial) => {
|
||||
@@ -114,7 +114,7 @@ function harness(filters, errors = {}) {
|
||||
const props = {
|
||||
filters,
|
||||
criteriaErrors: errors,
|
||||
items: { data: [], links: [] },
|
||||
items: { data: items, links: [] },
|
||||
options: { sectors: [], territories: [] },
|
||||
kinds: { institution: 'Instituição', fund: 'Fundo' },
|
||||
management: false,
|
||||
@@ -147,6 +147,69 @@ function harness(filters, errors = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
test('B03 broad coverage remains explicit and physical choice requests documented presence', () => {
|
||||
const h = harness({
|
||||
need: 'investment',
|
||||
territory: '7d908cf8-6e52-5141-8832-b1193985e39f',
|
||||
});
|
||||
assert.equal(h.select('Localização a pesquisar').props.value, 'coverage');
|
||||
h.select('Localização a pesquisar').props.onChange({
|
||||
target: { value: 'physical' },
|
||||
});
|
||||
h.render();
|
||||
assert.equal(h.form().data.location_mode, 'physical');
|
||||
assert.equal(h.form().data.certainty, 'documented');
|
||||
assert.match(
|
||||
text(h.tree()),
|
||||
/a cobertura indica onde o financiamento se aplica/,
|
||||
);
|
||||
});
|
||||
|
||||
test('B06 empty results omit institution alternatives and real result links keep exact identities', () => {
|
||||
const filters = {
|
||||
need: 'investment',
|
||||
territory: '4aa31470-997e-5c63-8fe0-ff2f62586f56',
|
||||
location_mode: 'physical',
|
||||
};
|
||||
const empty = harness(filters);
|
||||
assert.match(text(empty.tree()), /Não foram encontradas instituições/);
|
||||
assert.equal(
|
||||
nodes(empty.tree()).filter(
|
||||
(n) =>
|
||||
n.props?.href?.startsWith('/fundos/') &&
|
||||
n.props.href !== '/fundos/guardados',
|
||||
).length,
|
||||
0,
|
||||
);
|
||||
const fixture = JSON.parse(
|
||||
fs.readFileSync(
|
||||
'outputs/funding-b03-b06-20261120/fixture.json',
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
const originals = JSON.parse(
|
||||
fs.readFileSync(
|
||||
'database/data/funding-institutions-nov2026.json',
|
||||
'utf8',
|
||||
),
|
||||
).references;
|
||||
const items = Object.entries(fixture.records).map(([key, r]) => ({
|
||||
id: r.id,
|
||||
payload: originals[key].draft,
|
||||
}));
|
||||
const h = harness(filters, {}, items);
|
||||
for (const item of items) {
|
||||
const link = nodes(h.tree()).find(
|
||||
(n) =>
|
||||
text(n) === item.payload.title &&
|
||||
n.props?.href?.startsWith('/fundos/'),
|
||||
);
|
||||
assert.ok(link, item.payload.title);
|
||||
assert.ok(link.props.href.startsWith('/fundos/' + item.id + '?'));
|
||||
assert.match(link.props.href, /location_mode=physical/);
|
||||
}
|
||||
});
|
||||
|
||||
void test('searching another province resets only the search location and preserves the investment scope', () => {
|
||||
const filters = {
|
||||
category: 'banking',
|
||||
|
||||
Reference in New Issue
Block a user