From 7d787fa3b38a0924cbebccc1af8c8c20dad78738 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 23:22:30 +0200 Subject: [PATCH] =?UTF-8?q?Dossier:=20a=20actividade=20principal=20=C3=A9?= =?UTF-8?q?=20a=20mesma=20em=20todos=20os=20menus,=20com=20ou=20sem=20opor?= =?UTF-8?q?tunidade=20escolhida?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM --- app/Services/InvestmentConsumerScope.php | 5 ++++ .../InvestmentContextContinuityTest.php | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/Services/InvestmentConsumerScope.php b/app/Services/InvestmentConsumerScope.php index 297f4b0d..1dd6984d 100644 --- a/app/Services/InvestmentConsumerScope.php +++ b/app/Services/InvestmentConsumerScope.php @@ -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']); diff --git a/tests/Feature/InvestmentContextContinuityTest.php b/tests/Feature/InvestmentContextContinuityTest.php index aed60688..9c78ae4d 100644 --- a/tests/Feature/InvestmentContextContinuityTest.php +++ b/tests/Feature/InvestmentContextContinuityTest.php @@ -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.