true]); } public function test_public_catalogue_and_detail_exclude_reserved_fields_and_locations(): void { $business = $this->publishedBusiness(); $this->getJson('/api/v1/business-opportunities')->assertOk() ->assertJsonPath('data.0.title', 'Public synthetic opportunity') ->assertJsonMissingPath('data.0.owner_user_id') ->assertJsonMissingPath('data.0.payload') ->assertJsonMissingPath('data.0.geom'); $this->getJson('/api/v1/business-opportunities/'.$business['public_slug'])->assertOk() ->assertJsonPath('data.title', 'Public synthetic opportunity') ->assertJsonMissingPath('data.payload') ->assertJsonMissingPath('data.owner_user_id'); } public function test_interest_is_limited_to_published_business_and_deduplicated_idempotently(): void { $business = $this->publishedBusiness(); $payload = [ 'existingBusinessId' => $business['id'], 'modality' => 'company_sale', 'fullName' => 'Synthetic investor', 'email' => 'portal-integration-test@gmail.com', 'phone' => '+258 840000000', 'investorType' => 'empresa', 'country' => 'Moçambique', 'sectorInterest' => 'Energia', 'message' => 'Synthetic interest for the published business listing.', 'privacyConsent' => true, ]; $key = (string) Str::uuid(); $first = $this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => $key])->assertCreated(); $second = $this->postJson('/api/v1/interest-requests', $payload, ['Idempotency-Key' => $key])->assertCreated(); $this->assertSame($first->json(), $second->json()); $this->assertDatabaseHas('interest_requests', [ 'existing_business_id' => $business['id'], 'modality' => 'company_sale', 'status' => 'received', ]); $this->assertDatabaseCount('interest_requests', 1); $this->assertDatabaseCount('outbox_events', 1); $this->postJson('/api/v1/interest-requests', [...$payload, 'message' => 'Another valid message for this active interest.']) ->assertStatus(409); $this->assertDatabaseCount('interest_requests', 1); } /** @return array{id:string,public_slug:string} */ private function publishedBusiness(): array { $id = (string) Str::uuid(); $slug = 'public-synthetic-'.$id; $now = now(); DB::table('existing_businesses')->insert([ 'id' => $id, 'code' => 'SYN-'.strtoupper(substr(str_replace('-', '', $id), 0, 12)), 'owner_user_id' => User::factory()->create()->id, 'modality' => 'company_sale', 'status' => 'published', 'classification' => 'confidential', 'version_no' => 1, 'payload' => Crypt::encryptString(json_encode(['title' => 'Private synthetic title'], JSON_THROW_ON_ERROR)), 'public_title' => 'Public synthetic opportunity', 'public_slug' => $slug, 'published_at' => $now, 'created_at' => $now, 'updated_at' => $now, ]); return ['id' => $id, 'public_slug' => $slug]; } }