fix(portfolio): embed documented public opportunities with QA evidence
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { compileFunction } from 'node:vm';
|
||||
import { createRequire } from 'node:module';
|
||||
import React from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import ts from 'typescript';
|
||||
import * as catalogue from '../../resources/js/lib/catalogue-context.ts';
|
||||
import * as territory from '../../resources/js/lib/search-territory.ts';
|
||||
const require = createRequire(import.meta.url);
|
||||
const Frame = ({ children }) => React.createElement('main', null, children);
|
||||
const shared = {
|
||||
Layout: Frame,
|
||||
Management: Frame,
|
||||
Field: ({ children }) => React.createElement('label', null, children),
|
||||
control: '',
|
||||
button: '',
|
||||
Pagination: () => null,
|
||||
kind: () => '',
|
||||
};
|
||||
const module = { exports: {} };
|
||||
compileFunction(
|
||||
ts.transpileModule(
|
||||
fs.readFileSync('resources/js/pages/portfolio/index.tsx', 'utf8'),
|
||||
{
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
jsx: ts.JsxEmit.ReactJSX,
|
||||
},
|
||||
},
|
||||
).outputText,
|
||||
['require', 'module', 'exports'],
|
||||
)(
|
||||
(name) => {
|
||||
if (name === '@inertiajs/react')
|
||||
return {
|
||||
Link: ({ href, children }) =>
|
||||
React.createElement('a', { href }, children),
|
||||
useForm: (data) => ({ data, setData() {}, get() {} }),
|
||||
usePage: () => ({ url: '/carteira?q=Soja' }),
|
||||
};
|
||||
if (name === '@/lib/catalogue-context') return catalogue;
|
||||
if (name === '@/lib/search-territory') return territory;
|
||||
if (name === '@/components/investment-territory')
|
||||
return { TerritoryFields: () => null };
|
||||
if (name === '../management/shared' || name === './shared')
|
||||
return shared;
|
||||
return require(name);
|
||||
},
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
const page = (data) =>
|
||||
renderToStaticMarkup(
|
||||
React.createElement(module.exports.default, {
|
||||
management: false,
|
||||
records: { data: [] },
|
||||
filters: { q: 'Soja' },
|
||||
publishedOpportunities: { data },
|
||||
territorySelection: [],
|
||||
sectors: [],
|
||||
}),
|
||||
);
|
||||
test('real documentary opportunity appears within the empty portfolio consultation with its own detail link', () => {
|
||||
// Existing public QA record, from the unchanged documentary corridor source.
|
||||
const source = JSON.parse(
|
||||
fs.readFileSync(
|
||||
'database/data/corridor-investment-opportunities.json',
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
const summary = source.groups
|
||||
.find((g) => g.name === 'Corredor da Beira')
|
||||
.opportunities.find((o) => o.chain === 'Soja').description;
|
||||
const html = page([
|
||||
{
|
||||
id: 287,
|
||||
slug: 'inv-mz-gen-5563232446855414',
|
||||
title: 'Soja — Corredor da Beira',
|
||||
summary,
|
||||
location: 'Localização não indicada',
|
||||
},
|
||||
]);
|
||||
assert.match(html, /Oportunidades publicadas nesta consulta/);
|
||||
assert.match(html, /Soja — Corredor da Beira/);
|
||||
assert.match(
|
||||
html,
|
||||
/href="\/oportunidades\/inv-mz-gen-5563232446855414\?catalogue_query=q%3DSoja"/,
|
||||
);
|
||||
assert.match(html, /Localização não indicada/);
|
||||
});
|
||||
test('no matching public observations produce an explicit empty state rather than invented cards', () => {
|
||||
const html = page([]);
|
||||
assert.match(
|
||||
html,
|
||||
/Não há oportunidades publicadas com correspondência documentada/,
|
||||
);
|
||||
assert.doesNotMatch(html, /inv-mz-gen-/);
|
||||
});
|
||||
Reference in New Issue
Block a user