'Pessoa sintética QA', 'email' => 'portal-integration-test@gmail.com', 'investorType' => 'individual', 'country' => 'Moçambique', 'sectorInterest' => 'Energia', 'message' => 'Pedido exclusivamente sintético na base QA.', 'privacyConsent' => true]; } public function test_public_api_preserves_explicit_origin_in_receipt_replay_and_statistics(): void { $this->actingAs(User::factory()->create()); config(['portal.notifications_enabled' => false]); $headers = ['Idempotency-Key' => (string) Str::uuid()]; $data = [...$this->payload(), 'declared_origin_country_code' => 'PT']; $this->postJson('/api/v1/interest-requests', [...$data, 'declared_origin_country_code' => 'ZZ'], $headers)->assertUnprocessable()->assertJsonValidationErrors('declared_origin_country_code'); $this->assertDatabaseCount('interest_requests', 0); $first = $this->postJson('/api/v1/interest-requests', $data, $headers)->assertCreated()->json(); $this->postJson('/api/v1/interest-requests', $data, $headers)->assertCreated()->assertExactJson($first); $this->postJson('/api/v1/interest-requests', [...$data, 'declared_origin_country_code' => 'ZA'], $headers)->assertConflict(); $interest = InterestRequest::firstOrFail(); $this->assertSame('PT', $interest->metadata['declared_origin_country_code']); $this->assertSame('Moçambique', $interest->country); $this->assertDatabaseCount('interest_requests', 1); $this->postJson('/api/v1/interest-requests', $this->payload(), ['Idempotency-Key' => (string) Str::uuid()])->assertCreated(); $manager = User::factory()->create(); config(['portal.managers' => [$manager->email]]); $this->actingAsWithMfa($manager); $stats = app(DeclaredOriginStatistics::class)->forManager($manager); $this->assertSame([null, 'PT'], array_column($stats['interests'], 'code')); $this->assertSame([1, 1], array_column($stats['interests'], 'count')); } public function test_support_form_keeps_origin_optional_and_exposes_local_catalogue(): void { $this->withoutVite(); $this->get('/apoio')->assertInertia(fn (Assert $page) => $page->has('countries', 249)); $this->get('/manifestar-interesse')->assertInertia(fn (Assert $page) => $page->has('countries', 249)); $data = [...$this->payload(), 'kind' => 'support', 'submission_key' => (string) Str::uuid(), 'declared_origin_country_code' => 'ZA']; $this->postJson('/apoio', [...$data, 'declared_origin_country_code' => 'ZZ'])->assertUnprocessable(); $this->assertDatabaseCount('interest_requests', 0); $this->from('/apoio')->post('/apoio', $data)->assertRedirect('/apoio')->assertSessionHasNoErrors(); $this->assertSame('ZA', InterestRequest::firstOrFail()->metadata['declared_origin_country_code']); $this->post('/apoio', $data)->assertSessionHasNoErrors(); $this->assertDatabaseCount('interest_requests', 1); } }