fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -13,15 +13,17 @@ use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PortalManagementTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_catalog_filters_combine_and_survive_pagination(): void
|
||||
{
|
||||
$this->actingAs($this->manager());
|
||||
$this->actingAsWithMfa($this->manager());
|
||||
$sector = $this->sector();
|
||||
for ($i = 0; $i < 22; $i++) {
|
||||
Opportunity::create(['sector_id' => $sector->id, 'reference' => 'SOL-'.$i,
|
||||
@@ -44,7 +46,7 @@ class PortalManagementTest extends TestCase
|
||||
|
||||
public function test_unspecified_geography_has_a_private_review_filter_without_assigning_a_location(): void
|
||||
{
|
||||
$this->actingAs($this->manager());
|
||||
$this->actingAsWithMfa($this->manager());
|
||||
$sector = $this->sector();
|
||||
$pending = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'GEO-PENDING', 'slug' => 'geo-pending',
|
||||
'title' => 'Pendência territorial', 'status' => 'published', 'published_at' => now()->subMinute(),
|
||||
@@ -94,16 +96,17 @@ class PortalManagementTest extends TestCase
|
||||
$this->actingAs($user)->get('/management/interests')->assertForbidden();
|
||||
$this->post('/management/sectors', ['name' => 'Intruso'])->assertForbidden();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAsWithMfa($user);
|
||||
$user->forceFill(['email_verified_at' => null])->save();
|
||||
$this->get('/management/interests')->assertRedirect(route('verification.notice'));
|
||||
$this->actingAs($this->manager())->get('/management/interests')->assertOk();
|
||||
$this->actingAsWithMfa($this->manager())->get('/management/interests')->assertOk();
|
||||
}
|
||||
|
||||
public function test_manager_creates_and_edits_sectors_and_invalidates_home_cache(): void
|
||||
{
|
||||
$this->actingAs($this->manager());
|
||||
$this->actingAsWithMfa($this->manager());
|
||||
Cache::put('portal_home_pt', ['old' => true]);
|
||||
$data = ['name' => 'Energia', 'slug' => 'energia', 'sort_order' => 1, 'is_active' => true];
|
||||
$data = ['name' => 'Energia', 'slug' => 'energia', 'sort_order' => 1, 'is_active' => true, 'editorial_published' => false];
|
||||
$this->post('/management/sectors', $data)->assertRedirect('/management/sectors');
|
||||
$this->assertNull(Cache::get('portal_home_pt'));
|
||||
$sector = Sector::firstOrFail();
|
||||
@@ -116,9 +119,9 @@ class PortalManagementTest extends TestCase
|
||||
|
||||
public function test_draft_money_precision_is_preserved_without_editorial_publication_bypass(): void
|
||||
{
|
||||
$this->actingAs($this->manager());
|
||||
$this->actingAsWithMfa($this->manager());
|
||||
$data = ['sector_id' => $this->sector()->id, 'reference' => 'INV-TEST', 'title' => 'Solar',
|
||||
'slug' => 'solar', 'status' => 'draft', 'is_featured' => true, 'maturity_level' => 4,
|
||||
'slug' => 'solar', 'is_featured' => true, 'maturity_level' => 4,
|
||||
'estimated_investment_amount' => '1234567890123456.78', 'estimated_investment_currency' => 'MZN'];
|
||||
$this->postJson('/management/opportunities/drafts', [...$data, 'creation_key' => (string) Str::uuid(), 'reason' => 'Rascunho financeiro incompleto em QA'])->assertCreated();
|
||||
$opportunity = Opportunity::firstOrFail();
|
||||
@@ -135,7 +138,7 @@ class PortalManagementTest extends TestCase
|
||||
$interest = InterestRequest::create(['reference' => 'IR-TEST', 'full_name' => 'Pessoa de teste',
|
||||
'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->actingAsWithMfa($manager)->get('/management/interests/'.$interest->id)->assertOk();
|
||||
$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',
|
||||
@@ -170,19 +173,20 @@ class PortalManagementTest extends TestCase
|
||||
|
||||
public function test_public_requests_reject_missing_draft_deleted_and_future_opportunities(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
$opportunity = $this->opportunity(['status' => 'draft']);
|
||||
$payload = ['fullName' => 'Teste do portal', 'email' => 'invalid', 'investorType' => 'empresa',
|
||||
'country' => 'Moçambique', 'sectorInterest' => 'Energia', 'message' => 'Pedido para verificar o contrato.',
|
||||
'privacyConsent' => true, 'opportunityReference' => 'MISSING'];
|
||||
$this->postJson('/api/v1/interest-requests', $payload)->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$payload['opportunityReference'] = $opportunity->reference;
|
||||
$this->postJson('/api/v1/interest-requests', $payload)->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$opportunity->update(['status' => 'published', 'published_at' => now()->addDay()]);
|
||||
$this->getJson('/api/v1/opportunities/'.$opportunity->slug)->assertNotFound();
|
||||
$this->postJson('/api/v1/interest-requests', $payload)->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$opportunity->update(['published_at' => now()->subMinute()]);
|
||||
$opportunity->delete();
|
||||
$this->postJson('/api/v1/interest-requests', $payload)->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertUnprocessable()->assertJsonValidationErrors('opportunityReference');
|
||||
$this->assertDatabaseCount('interest_requests', 0);
|
||||
}
|
||||
|
||||
@@ -199,7 +203,7 @@ class PortalManagementTest extends TestCase
|
||||
'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', [
|
||||
$this->actingAsWithMfa($manager)->patch('/management/interests/'.$interest->id.'/consent/proponent', [
|
||||
'reason' => 'O titular pediu para não partilhar os seus dados com o proponente.',
|
||||
])->assertRedirect();
|
||||
|
||||
@@ -227,14 +231,14 @@ class PortalManagementTest extends TestCase
|
||||
'interest_request_id' => $interest->id, 'policy_version' => '2026-09-30',
|
||||
'created_at' => now(), 'updated_at' => now()]);
|
||||
|
||||
$this->actingAs($manager)->get('/management/interests/'.$interest->id)
|
||||
$this->actingAsWithMfa($manager)->get('/management/interests/'.$interest->id)
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->where('consents.0.purpose', 'respond_to_interest')->where('consents.0.status', 'granted'));
|
||||
$this->actingAs(User::factory()->create())
|
||||
->patch('/management/interests/'.$interest->id.'/consent/contact', [
|
||||
'reason' => 'O titular pediu para cessar o contacto sobre o pedido.',
|
||||
])->assertForbidden();
|
||||
$this->actingAs($manager);
|
||||
$this->actingAsWithMfa($manager);
|
||||
$this->patch('/management/interests/'.$interest->id.'/consent/contact', [
|
||||
'reason' => 'O titular pediu para cessar o contacto sobre o pedido.',
|
||||
])->assertRedirect();
|
||||
@@ -283,18 +287,19 @@ class PortalManagementTest extends TestCase
|
||||
|
||||
public function test_valid_public_submissions_persist_and_return_distinct_references(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
// DNS validation remains enabled; no mail is sent by this endpoint.
|
||||
$opportunity = $this->opportunity();
|
||||
$payload = ['fullName' => 'Pessoa de teste', 'email' => 'portal-integration-test@gmail.com',
|
||||
'investorType' => 'empresa', 'country' => 'Moçambique', 'sectorInterest' => 'Energia',
|
||||
'message' => 'Pedido fictício na base isolada de testes.', 'privacyConsent' => true,
|
||||
'opportunityReference' => $opportunity->reference];
|
||||
$first = $this->postJson('/api/v1/interest-requests', $payload)->assertCreated()->json('data.reference');
|
||||
$second = $this->postJson('/api/v1/interest-requests', $payload)->assertCreated()->json('data.reference');
|
||||
'opportunityReference' => null];
|
||||
$first = $this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.reference');
|
||||
$second = $this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.reference');
|
||||
$this->assertNotSame($first, $second);
|
||||
$this->assertMatchesRegularExpression('/^IR-\d{4}-[0-9A-Z]{26}$/', $first);
|
||||
$this->assertDatabaseHas('interest_requests', ['reference' => $first, 'opportunity_id' => $opportunity->id, 'privacy_consent' => true]);
|
||||
$this->postJson('/api/v1/interest-requests', [...$payload, 'privacyConsent' => false])->assertUnprocessable()->assertJsonValidationErrors('privacyConsent');
|
||||
$this->assertDatabaseHas('interest_requests', ['reference' => $first, 'opportunity_id' => null, 'privacy_consent' => true]);
|
||||
$this->postJson('/api/v1/interest-requests', [...$payload, 'privacyConsent' => false], ['Idempotency-Key' => (string) Str::uuid()])->assertUnprocessable()->assertJsonValidationErrors('privacyConsent');
|
||||
$this->assertDatabaseCount('interest_requests', 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user