Dossier: a actividade principal é a mesma em todos os menus, com ou sem oportunidade escolhida
tests / ci (push) Waiting to run

Cada página lê o dossier no âmbito da oportunidade em tratamento. Quando o
dossier tinha oportunidades associadas, o sector do dossier era substituído
pelo sector da oportunidade (um dossier «Criar Hotel» passava a mostrar
agronegócio) e, sem oportunidade escolhida, desaparecia. O mesmo dossier
mostrava assim valores diferentes conforme o menu.

A actividade principal do dossier passa a ser mantida em todos os âmbitos.
Só um dossier sem actividade própria recebe a da oportunidade escolhida;
localização, parque, regime e descrição continuam a seguir a oportunidade,
como até aqui.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
Claude
2026-12-04 23:26:33 +02:00
committed by nala
parent 09fc8ec0dd
commit 7d787fa3b3
2 changed files with 29 additions and 0 deletions
+5
View File
@@ -60,6 +60,11 @@ final class InvestmentConsumerScope
$choice = $key ? collect(StructuredData::collectionItems($choices))->firstWhere('opportunity.key', $key) : null;
abort_if($key && ! $choice, 422, 'Escolha uma oportunidade deste dossier.');
$specific = ['project_summary', 'sector_id', 'sector', 'province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'special_zone_id', 'investment_regime'];
// The dossier's primary activity is the investor's intention, the same in every menu:
// an opportunity of another sector neither replaces it nor makes it disappear (mapa de erros, "Criar Hotel").
// Only a dossier without its own activity takes the activity of the chosen opportunity.
$intention = array_keys(array_filter(Arr::only($context['fields'] ?? [], InvestorContext::INTENTION_FIELDS), fn ($value) => $value !== null && $value !== ''));
$specific = array_values(array_diff($specific, $intention));
$context['fields'] = Arr::except($context['fields'], $specific);
$context['provenance'] = Arr::except($context['provenance'] ?? [], $specific);
$context['selection'] = Arr::except($context['selection'], ['opportunity', 'territory', 'park']);
@@ -4,6 +4,7 @@ namespace Tests\Feature;
use App\Models\Sector;
use App\Models\User;
use App\Services\InvestmentConsumerScope;
use App\Services\InvestmentZones;
use App\Services\InvestorPath;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@@ -140,6 +141,29 @@ class InvestmentContextContinuityTest extends TestCase
$this->assertArrayNotHasKey('sector_id', $this->getJson('/investimentos/'.$id.'/contexto')->json('context.fields'));
}
public function test_an_opportunity_of_another_sector_does_not_change_the_dossier_activity_in_any_menu(): void
{
// Mapa de erros, "Criar Hotel": the same dossier shows the same activity whichever opportunity scopes the page.
[$tourism, $agro] = array_map(fn (string $name) => Sector::forceCreate(['name' => 'SINTÉTICO QA '.$name, 'slug' => 'sintetico-qa-'.Str::lower(Str::random(12)), 'is_active' => true]), ['Hotelaria', 'Agronegócio']);
$choice = fn (string $key) => ['opportunity' => ['key' => $key, 'kind' => 'opportunity', 'id' => $key, 'title' => 'SINTÉTICO QA '.$key, 'version' => 1, 'sha256' => str_repeat('a', 64),
'fields' => ['sector_id' => (string) $agro->id, 'sector' => $agro->name, 'project_summary' => 'Resumo da oportunidade']], 'territory' => null, 'park' => null];
$hotel = ['fields' => ['project_title' => 'Criar Hotel', 'sector_id' => (string) $tourism->id, 'sector' => $tourism->name, 'project_summary' => 'Hotel de 40 quartos'],
'selection' => [], 'provenance' => [], 'opportunity_choices' => [$choice('opportunity:qa-1'), $choice('opportunity:qa-2')]];
$scope = app(InvestmentConsumerScope::class);
foreach ([null, 'opportunity:qa-1', 'opportunity:qa-2'] as $opportunity) {
$fields = $scope->context($hotel, $opportunity)['fields'];
$this->assertSame([(string) $tourism->id, $tourism->name], [$fields['sector_id'], $fields['sector']], 'menu scoped by '.($opportunity ?? 'no opportunity'));
}
// Opportunity-specific data still follows the chosen opportunity.
$this->assertSame('Resumo da oportunidade', $scope->context($hotel, 'opportunity:qa-1')['fields']['project_summary']);
// A dossier without its own activity still takes the activity of the opportunity being prepared.
$open = [...$hotel, 'fields' => ['project_title' => 'Ideia por definir']];
$this->assertSame((string) $agro->id, $scope->context($open, 'opportunity:qa-1')['fields']['sector_id']);
$this->assertArrayNotHasKey('sector_id', $scope->context($open, null)['fields']);
}
public function test_the_business_plan_executive_summary_fields_are_saved_in_the_draft(): void
{
// Investor report model: objectives, mission and keys to success are requested from the investor.