novas funcionalidades dos formulario
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-02 11:13:37 +02:00
parent a6afb4e97a
commit 4f35313d06
104 changed files with 7653 additions and 178 deletions
+76 -1
View File
@@ -8,6 +8,9 @@ use App\Models\Sector;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Inertia\Testing\AssertableInertia;
use Tests\TestCase;
@@ -120,9 +123,35 @@ class PortalManagementTest extends TestCase
'email' => 'test@example.invalid', 'investor_type' => 'empresa', 'country' => 'Moçambique',
'sector_interest' => 'Energia', 'message' => 'Pedido de informação para teste.', 'privacy_consent' => true]);
$this->actingAs($manager)->get('/management/interests/'.$interest->id)->assertOk();
$this->patch('/management/interests/'.$interest->id, ['status' => 'in_review', 'reviewed_by' => 999])->assertRedirect();
$this->patch('/management/interests/'.$interest->id, ['status' => 'in_review', 'reviewed_by' => 999,
'next_action' => 'Contactar o investidor', 'next_action_due_at' => now()->addDays(2)->toDateString(), 'assigned_to' => $manager->id,
'note' => 'O pedido foi recebido e encaminhado para análise interna.', 'next_action' => 'Contactar o investidor',
'next_action_due_at' => now()->addDays(2)->toDateString(), 'assigned_to' => $manager->id])->assertRedirect();
$this->assertSame($manager->id, $interest->fresh()->reviewed_by);
$this->assertNotNull($interest->fresh()->reviewed_at);
$transition = DB::table('business_workflow_transitions')->where('interest_request_id', $interest->id)->first();
$this->assertSame('received', $transition->from_status);
$this->assertSame('in_review', $transition->to_status);
$this->assertSame($manager->id, $interest->fresh()->assigned_to);
$this->assertDatabaseHas('tasks', ['interest_request_id' => $interest->id, 'assignee_user_id' => $manager->id,
'title' => 'Contactar o investidor', 'status' => 'open']);
$this->patch('/management/interests/'.$interest->id, ['status' => 'in_review', 'next_action' => 'Contactar o investidor',
'next_action_due_at' => now()->addDays(2)->toDateString(), 'assigned_to' => $manager->id])->assertRedirect();
$this->assertSame(1, DB::table('tasks')->where('interest_request_id', $interest->id)->where('status', 'open')->count());
$this->assertDatabaseHas('tasks', ['interest_request_id' => $interest->id, 'assignee_user_id' => $manager->id,
'title' => 'Contactar o investidor', 'status' => 'open']);
$this->patch('/management/interests/'.$interest->id, ['status' => 'in_review', 'next_action' => 'Enviar resumo ao investidor',
'next_action_due_at' => now()->addDays(4)->toDateString(), 'assigned_to' => $manager->id])->assertRedirect();
$this->assertDatabaseHas('tasks', ['interest_request_id' => $interest->id, 'title' => 'Contactar o investidor',
'status' => 'cancelled', 'outcome' => 'superseded']);
$this->assertSame(1, DB::table('tasks')->where('interest_request_id', $interest->id)->where('status', 'open')->count());
$this->patch('/management/interests/'.$interest->id, ['status' => 'in_review'])->assertRedirect();
$this->assertSame('Enviar resumo ao investidor', $interest->fresh()->next_action);
$this->get('/management/interests?follow_up=upcoming')->assertInertia(fn (AssertableInertia $page) => $page
->component('management/interests')->where('requests.data.0.reference', 'IR-TEST')->where('filters.follow_up', 'upcoming'));
$this->assertSame('O pedido foi recebido e encaminhado para análise interna.', Crypt::decryptString($transition->reason));
$this->assertSame($manager->id, $interest->fresh()->assigned_to);
$this->patch('/management/interests/'.$interest->id, ['status' => 'received'])->assertSessionHasErrors('status');
$this->patch('/management/interests/'.$interest->id, ['status' => 'invalid'])->assertSessionHasErrors('status');
}
@@ -144,6 +173,52 @@ class PortalManagementTest extends TestCase
$this->assertDatabaseCount('interest_requests', 0);
}
public function test_proponent_sharing_consent_can_be_revoked_with_audited_outbox_event(): void
{
$manager = $this->manager();
$interest = InterestRequest::create(['reference' => 'IR-CONSENT', 'full_name' => 'Pessoa de teste',
'email' => 'consent@example.invalid', 'investor_type' => 'empresa', 'country' => 'MZ',
'sector_interest' => 'Energia', 'message' => 'Pedido de partilha para teste.', 'privacy_consent' => true]);
$shareConsentId = (string) Str::uuid();
DB::table('consents')->insert(['id' => $shareConsentId, 'source_system' => 'portal-intake',
'external_id' => 'test-share-consent', 'version_no' => 1, 'data_classification' => 'confidential',
'correlation_id' => (string) Str::uuid(), 'subject_ref' => $interest->reference,
'purpose' => 'share_contact_with_proponent', 'status' => 'granted', 'granted_at' => now(),
'interest_request_id' => $interest->id, 'policy_version' => '2026-09-30', 'created_at' => now(), 'updated_at' => now()]);
$this->actingAs($manager)->patch('/management/interests/'.$interest->id.'/consent/proponent', [
'reason' => 'O titular pediu para não partilhar os seus dados com o proponente.',
])->assertRedirect();
$this->assertDatabaseHas('consents', ['id' => $shareConsentId, 'status' => 'withdrawn']);
$this->assertDatabaseHas('business_workflow_transitions', ['interest_request_id' => $interest->id,
'to_status' => 'received']);
$event = DB::table('outbox_events')->where('event_type', 'InterestConsentWithdrawn')->first();
$this->assertNotNull($event);
$this->assertSame($shareConsentId, $event->aggregate_id);
$this->assertStringNotContainsString('consent@example.invalid', $event->payload);
}
public function test_overdue_task_escalation_is_opt_in_and_idempotent(): void
{
$interest = InterestRequest::create(['reference' => 'IR-SLA', 'full_name' => 'Pessoa de teste',
'email' => 'sla@example.invalid', 'investor_type' => 'empresa', 'country' => 'MZ',
'sector_interest' => 'Energia', 'message' => 'Pedido de teste de escalada.', 'privacy_consent' => true]);
DB::table('tasks')->insert(['source_system' => 'portal-interest', 'external_id' => 'sla-test-task',
'version_no' => 1, 'data_classification' => 'confidential', 'correlation_id' => (string) Str::uuid(),
'interest_request_id' => $interest->id, 'task_type' => 'interest_follow_up', 'title' => 'Contactar',
'status' => 'open', 'priority' => 3, 'due_at' => now()->subHour(), 'created_at' => now(), 'updated_at' => now()]);
config(['existing-business.sla_escalation_enabled' => false]);
$this->artisan('investmoz:escalate-overdue-tasks')->assertSuccessful();
$this->assertDatabaseHas('tasks', ['external_id' => 'sla-test-task', 'priority' => 3]);
config(['existing-business.sla_escalation_enabled' => true]);
$this->artisan('investmoz:escalate-overdue-tasks')->assertSuccessful();
$this->artisan('investmoz:escalate-overdue-tasks')->assertSuccessful();
$this->assertDatabaseHas('tasks', ['external_id' => 'sla-test-task', 'priority' => 1, 'outcome' => 'sla_overdue']);
}
public function test_valid_public_submissions_persist_and_return_distinct_references(): void
{
// DNS validation remains enabled; no mail is sent by this endpoint.