fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+15 -8
View File
@@ -5,6 +5,7 @@ namespace Tests\Feature;
use App\Models\InterestRequest;
use App\Models\Opportunity;
use App\Models\Sector;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@@ -14,6 +15,12 @@ class InterestSubmissionTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->actingAs(User::factory()->create());
}
private function payload(): array
{
return ['fullName' => 'Pessoa de teste', 'email' => 'portal-integration-test@gmail.com',
@@ -29,6 +36,7 @@ class InterestSubmissionTest extends TestCase
InterestRequest::firstOrFail()->update(['status' => 'closed']);
$second = $this->postJson('/api/v1/interest-requests', $this->payload(), $headers)->assertCreated();
$this->assertSame($first->json(), $second->json());
$this->assertSame('closed', InterestRequest::firstOrFail()->status);
$this->assertDatabaseCount('interest_requests', 1);
$this->assertDatabaseCount('interest_submission_receipts', 1);
$this->assertDatabaseCount('outbox_events', 1);
@@ -56,7 +64,7 @@ class InterestSubmissionTest extends TestCase
public function test_proponent_sharing_is_a_separate_optional_versioned_consent(): void
{
$this->postJson('/api/v1/interest-requests', [...$this->payload(), 'shareWithProponent' => true])->assertCreated();
$this->postJson('/api/v1/interest-requests', [...$this->payload(), 'shareWithProponent' => true], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
$interest = InterestRequest::firstOrFail();
$this->assertDatabaseHas('consents', ['interest_request_id' => $interest->id,
'purpose' => 'respond_to_interest', 'status' => 'granted']);
@@ -65,14 +73,13 @@ class InterestSubmissionTest extends TestCase
$this->assertSame(2, DB::table('consents')->where('interest_request_id', $interest->id)->count());
}
public function test_old_clients_still_work_and_distinct_keys_create_distinct_submissions(): void
public function test_missing_key_is_refused_and_distinct_general_requests_have_separate_identities(): void
{
$this->postJson('/api/v1/interest-requests', $this->payload())->assertCreated();
foreach ([Str::uuid(), Str::uuid()] as $key) {
$this->postJson('/api/v1/interest-requests', $this->payload(), ['Idempotency-Key' => (string) $key])->assertCreated();
}
$this->assertDatabaseCount('interest_requests', 3);
$this->assertDatabaseCount('outbox_events', 3);
$this->postJson('/api/v1/interest-requests', $this->payload())->assertUnprocessable();
$this->postJson('/api/v1/interest-requests', $this->payload(), ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
$this->postJson('/api/v1/interest-requests', $this->payload(), ['Idempotency-Key' => (string) Str::uuid()])->assertCreated();
$this->assertDatabaseCount('interest_requests', 2);
$this->assertDatabaseCount('outbox_events', 2);
$this->assertDatabaseCount('interest_submission_receipts', 2);
}