@@ -10,6 +10,7 @@ use App\Models\Lead;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CrmIntakeTest extends TestCase
|
||||
@@ -27,8 +28,17 @@ class CrmIntakeTest extends TestCase
|
||||
|
||||
private function interest(string $reference = 'IR-CRM-1'): InterestRequest
|
||||
{
|
||||
return InterestRequest::create(['reference' => $reference, 'full_name' => 'Contacto fictício', 'email' => 'CONTACT@example.invalid',
|
||||
$interest = InterestRequest::create(['reference' => $reference, 'full_name' => 'Contacto fictício', 'email' => 'CONTACT@example.invalid',
|
||||
'investor_type' => 'empresa', 'country' => 'Moçambique', 'sector_interest' => 'Energia', 'message' => 'Mensagem do pedido de teste.', 'privacy_consent' => true]);
|
||||
DB::table('consents')->insert([
|
||||
'id' => (string) Str::uuid(), 'source_system' => 'portal-intake', 'external_id' => 'CrmTestConsent:'.$reference,
|
||||
'version_no' => 1, 'data_classification' => 'confidential', 'subject_ref' => $interest->reference,
|
||||
'purpose' => 'respond_to_interest', 'status' => 'granted', 'granted_at' => now(),
|
||||
'interest_request_id' => $interest->id, 'policy_version' => 'test-policy-v1',
|
||||
'created_at' => now(), 'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $interest;
|
||||
}
|
||||
|
||||
private function data(User $user): array
|
||||
@@ -72,6 +82,30 @@ class CrmIntakeTest extends TestCase
|
||||
$this->assertDatabaseCount('leads', 2);
|
||||
}
|
||||
|
||||
public function test_conversion_rechecks_the_canonical_contact_consent_record(): void
|
||||
{
|
||||
$user = $this->setupManager();
|
||||
$interest = $this->interest();
|
||||
DB::table('consents')->where('interest_request_id', $interest->id)
|
||||
->where('purpose', 'respond_to_interest')
|
||||
->update(['status' => 'withdrawn', 'withdrawn_at' => now(), 'updated_at' => now()]);
|
||||
|
||||
$this->post('/management/crm/convert/'.$interest->id, $this->data($user))
|
||||
->assertSessionHasErrors('investor_id');
|
||||
|
||||
$this->assertDatabaseCount('leads', 0);
|
||||
$this->assertDatabaseCount('investors', 0);
|
||||
$this->assertDatabaseCount('contacts', 0);
|
||||
$this->assertDatabaseCount('tasks', 0);
|
||||
|
||||
DB::table('consents')->where('interest_request_id', $interest->id)->update([
|
||||
'status' => 'granted', 'withdrawn_at' => null, 'deleted_at' => now(), 'updated_at' => now(),
|
||||
]);
|
||||
$this->post('/management/crm/convert/'.$interest->id, $this->data($user))
|
||||
->assertSessionHasErrors('investor_id');
|
||||
$this->assertDatabaseCount('leads', 0);
|
||||
}
|
||||
|
||||
public function test_unauthorised_users_cannot_convert_and_input_requires_owner_and_future_action(): void
|
||||
{
|
||||
$user = $this->setupManager();
|
||||
|
||||
Reference in New Issue
Block a user