Em produção, os pedidos de interesse feitos em /apoio nunca foram vistos: só o caminho da API enfileirava o aviso à equipa. O aviso passa para o InterestSubmission::receive, por onde passam todos os caminhos de entrada, e a submissão de um pedido no Balcão Virtual passa a avisar também a equipa (até aqui só o proponente e um analista já atribuído recebiam aviso interno). - TeamNotifications: fila transaccional comum (só existe aviso se o registo ficou gravado); destinatários de PORTAL_NOTIFICATION_RECIPIENTS, sem dados pessoais nas mensagens. - NotifyDeskRequestSubmitted: protocolo e ligações protegidas de triagem. - DemographicInstallation aceita também o domínio público como a mesma instalação de produção, para o APP_URL poder passar a investemoz.tempo.co.mz. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jm
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\NotifyDeskRequestSubmitted;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Mail\MailManager;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** A submitted Virtual Desk request must reach the team, not only the investor's own inbox. */
|
||||
final class DeskSubmissionTeamNoticeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $owner;
|
||||
|
||||
private string $requestId;
|
||||
|
||||
private array $answers = ['title' => 'SYNTHETIC project', 'description' => 'SYNTHETIC private preparation',
|
||||
'original_reference' => 'SYNTHETIC-REF', 'change_reason' => 'SYNTHETIC confidential change'];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutVite();
|
||||
$this->owner = User::factory()->create(['email' => 'investidor-sintetico@example.invalid']);
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email], 'investmoz_ai.enabled' => false, 'suitecrm.enabled' => false,
|
||||
'portal.notifications_enabled' => true, 'portal.notification_recipients' => ['balcao@example.invalid']]);
|
||||
$edition = $this->actingAs($manager)->putJson('/management/balcao/servicos/project-change', ['base_version' => 0, 'definition' => config('virtual-desk.services.project-change'), 'confirm' => true, 'reason' => 'SYNTHETIC team notice acceptance QA'])->assertCreated()->json('id');
|
||||
$case = $this->actingAs($this->owner)->postJson('/balcao-virtual/dossiers', ['title' => 'SYNTHETIC dossier', 'client_key' => (string) Str::uuid(), 'reuse_consent' => true])->assertCreated()->json('id');
|
||||
$this->requestId = $this->postJson('/balcao-virtual/dossiers/'.$case.'/pedidos', ['service_version_id' => $edition, 'client_key' => (string) Str::uuid()])->assertCreated()->json('id');
|
||||
}
|
||||
|
||||
private function deskNotices(): int
|
||||
{
|
||||
return DB::table('jobs')->where('payload', 'like', '%NotifyDeskRequestSubmitted%')->count();
|
||||
}
|
||||
|
||||
public function test_drafts_do_not_notify_and_submission_notifies_once_without_personal_data(): void
|
||||
{
|
||||
$this->putJson('/balcao-virtual/pedidos/'.$this->requestId, ['version' => 1, 'payload' => $this->answers])->assertOk();
|
||||
$this->assertSame(0, $this->deskNotices());
|
||||
|
||||
$this->putJson('/balcao-virtual/pedidos/'.$this->requestId, ['version' => 2, 'payload' => $this->answers, 'submit' => true, 'consent' => true])->assertOk()->assertJsonPath('status', 'submitted');
|
||||
$this->assertSame(1, $this->deskNotices());
|
||||
$queued = DB::table('jobs')->pluck('payload')->implode(' ');
|
||||
$this->assertStringNotContainsString('investidor-sintetico@example.invalid', $queued);
|
||||
$this->assertStringNotContainsString('confidential change', $queued);
|
||||
|
||||
// Replaying the same submission does not send a second notice.
|
||||
$this->putJson('/balcao-virtual/pedidos/'.$this->requestId, ['version' => 2, 'payload' => $this->answers, 'submit' => true, 'consent' => true])->assertOk();
|
||||
$this->assertSame(1, $this->deskNotices());
|
||||
}
|
||||
|
||||
public function test_notice_names_the_protocol_and_triage_link_only(): void
|
||||
{
|
||||
$this->putJson('/balcao-virtual/pedidos/'.$this->requestId, ['version' => 1, 'payload' => $this->answers, 'submit' => true, 'consent' => true])->assertOk();
|
||||
$protocol = DB::table('desk_requests')->where('id', $this->requestId)->value('protocol');
|
||||
$job = new NotifyDeskRequestSubmitted($this->requestId, 'balcao@example.invalid');
|
||||
Mail::swap(\Mockery::mock(MailManager::class));
|
||||
Mail::shouldReceive('raw')->once()->withArgs(function ($body, $callback) use ($protocol) {
|
||||
$this->assertStringContainsString($protocol, $body);
|
||||
$this->assertStringContainsString('/management/balcao/atribuicoes', $body);
|
||||
$this->assertStringContainsString('sem responsável', $body);
|
||||
$this->assertStringNotContainsString('SYNTHETIC', $body);
|
||||
$this->assertStringNotContainsString('investidor-sintetico', $body);
|
||||
|
||||
return is_callable($callback);
|
||||
});
|
||||
$job->handle();
|
||||
|
||||
// A recipient removed from the configuration, or a request already in review, gets nothing.
|
||||
Mail::swap(\Mockery::mock(MailManager::class));
|
||||
Mail::shouldReceive('raw')->never();
|
||||
(new NotifyDeskRequestSubmitted($this->requestId, 'outro@example.invalid'))->handle();
|
||||
DB::table('desk_requests')->where('id', $this->requestId)->update(['status' => 'reviewing']);
|
||||
$job->handle();
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,32 @@ class PortalOperationsTest extends TestCase
|
||||
$this->assertDatabaseCount('interest_requests', 2);
|
||||
}
|
||||
|
||||
public function test_public_support_form_notifies_the_team_once_per_new_interest(): void
|
||||
{
|
||||
// Production received interests through /apoio for months without anyone being told.
|
||||
$payload = ['fullName' => '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, 'kind' => 'support'];
|
||||
config(['portal.notifications_enabled' => true, 'portal.notification_recipients' => ['equipa@example.invalid', 'gestao@example.invalid', 'equipa@example.invalid']]);
|
||||
$key = (string) Str::uuid();
|
||||
$this->post('/apoio', [...$payload, 'submission_key' => $key])->assertSessionHasNoErrors()->assertRedirect();
|
||||
$this->assertDatabaseCount('interest_requests', 1);
|
||||
$this->assertDatabaseCount('jobs', 2); // one per distinct recipient
|
||||
$queued = DB::table('jobs')->pluck('payload')->implode(' ');
|
||||
$this->assertStringContainsString('NotifyInterestReceived', $queued);
|
||||
$this->assertStringNotContainsString('portal-integration-test@gmail.com', $queued);
|
||||
|
||||
// Replaying the same submission returns the stored interest and does not notify again.
|
||||
$this->post('/apoio', [...$payload, 'submission_key' => $key])->assertSessionHasNoErrors()->assertRedirect();
|
||||
$this->assertDatabaseCount('interest_requests', 1);
|
||||
$this->assertDatabaseCount('jobs', 2);
|
||||
|
||||
config(['portal.notifications_enabled' => false]);
|
||||
$this->post('/apoio', [...$payload, 'submission_key' => (string) Str::uuid()])->assertSessionHasNoErrors();
|
||||
$this->assertDatabaseCount('interest_requests', 2);
|
||||
$this->assertDatabaseCount('jobs', 2);
|
||||
}
|
||||
|
||||
public function test_job_checks_current_configuration_and_excludes_personal_data(): void
|
||||
{
|
||||
$interest = InterestRequest::create(['reference' => 'IR-TEST', 'full_name' => 'Pessoa confidencial',
|
||||
|
||||
Reference in New Issue
Block a user