This commit is contained in:
@@ -67,8 +67,53 @@ class BusinessMarketplacePublicTest extends TestCase
|
||||
$this->assertDatabaseCount('interest_requests', 1);
|
||||
}
|
||||
|
||||
public function test_public_catalogue_filters_by_existing_opportunity_modality_and_opens_response_flow(): void
|
||||
{
|
||||
$business = $this->publishedBusiness('real_estate');
|
||||
$companySale = $this->publishedBusiness('company_sale');
|
||||
$landRight = $this->publishedBusiness('land_right');
|
||||
|
||||
$this->getJson('/api/v1/business-opportunities?modality=real_estate')->assertOk()
|
||||
->assertJsonCount(1, 'data')->assertJsonPath('data.0.modality', 'real_estate');
|
||||
$this->getJson('/api/v1/business-opportunities?modality=company_sale')->assertOk()
|
||||
->assertJsonCount(1, 'data')->assertJsonPath('data.0.modality', 'company_sale');
|
||||
$this->getJson('/api/v1/business-opportunities?modality=land_right')->assertOk()
|
||||
->assertJsonCount(1, 'data')->assertJsonPath('data.0.modality', 'land_right');
|
||||
|
||||
$this->get('/negocios?modality=real_estate')->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-marketplace')
|
||||
->where('filters.modality', 'real_estate')->has('results.data', 1));
|
||||
$this->get('/negocios/'.$business['public_slug'])->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-opportunity')
|
||||
->where('record.modality', 'real_estate'));
|
||||
$this->get('/negocios/'.$business['public_slug'].'/manifestar-interesse')->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-interest')
|
||||
->where('record.modality', 'real_estate'));
|
||||
$this->get('/negocios?modality=company_sale')->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-marketplace')
|
||||
->where('filters.modality', 'company_sale')->has('results.data', 1));
|
||||
$this->get('/negocios/'.$companySale['public_slug'])->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-opportunity')
|
||||
->where('record.modality', 'company_sale'));
|
||||
$this->get('/negocios?modality=land_right')->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-marketplace')
|
||||
->where('filters.modality', 'land_right')->has('results.data', 1));
|
||||
$this->get('/negocios/'.$landRight['public_slug'])->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business-opportunity')
|
||||
->where('record.modality', 'land_right'));
|
||||
|
||||
$this->postJson('/api/v1/interest-requests', [
|
||||
'existingBusinessId' => $business['id'], 'modality' => 'real_estate',
|
||||
'fullName' => 'Synthetic investor', 'email' => 'portal-integration-test@gmail.com', 'phone' => '+258 840000000',
|
||||
'investorType' => 'empresa', 'country' => 'MZ', 'sectorInterest' => 'Imobiliário',
|
||||
'message' => 'Synthetic interest in the published real estate opportunity.',
|
||||
'privacyConsent' => true,
|
||||
])->assertCreated();
|
||||
$this->assertDatabaseHas('interest_requests', ['existing_business_id' => $business['id'], 'modality' => 'real_estate', 'status' => 'received']);
|
||||
}
|
||||
|
||||
/** @return array{id:string,public_slug:string} */
|
||||
private function publishedBusiness(): array
|
||||
private function publishedBusiness(string $modality = 'company_sale'): array
|
||||
{
|
||||
$id = (string) Str::uuid();
|
||||
$slug = 'public-synthetic-'.$id;
|
||||
@@ -77,7 +122,7 @@ class BusinessMarketplacePublicTest extends TestCase
|
||||
'id' => $id,
|
||||
'code' => 'SYN-'.strtoupper(substr(str_replace('-', '', $id), 0, 12)),
|
||||
'owner_user_id' => User::factory()->create()->id,
|
||||
'modality' => 'company_sale',
|
||||
'modality' => $modality,
|
||||
'status' => 'published',
|
||||
'classification' => 'confidential',
|
||||
'version_no' => 1,
|
||||
|
||||
@@ -195,4 +195,43 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
$this->assertStringContainsString('Synthetic holder', $snapshot);
|
||||
$this->actingAs(User::factory()->create())->getJson($this->base.'/'.$first)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_company_sale_real_estate_and_land_right_have_distinct_private_subject_records(): void
|
||||
{
|
||||
$owner = User::factory()->create();
|
||||
$this->actingAs($owner);
|
||||
$cases = [
|
||||
['modality' => 'company_sale', 'kind' => 'company', 'label' => 'Synthetic company sale'],
|
||||
['modality' => 'real_estate', 'kind' => 'property', 'label' => 'Synthetic commercial property'],
|
||||
['modality' => 'land_right', 'kind' => 'land_right', 'label' => 'Synthetic declared land right'],
|
||||
];
|
||||
|
||||
foreach ($cases as $case) {
|
||||
$businessId = $this->postJson($this->base, [
|
||||
'modality' => $case['modality'],
|
||||
'classification' => 'confidential',
|
||||
'reason' => 'Synthetic modality-specific QA draft',
|
||||
'payload' => ['title' => $case['label'], 'wizard_version' => '2', 'wizard_step' => '6'],
|
||||
])->assertCreated()->json('id');
|
||||
|
||||
$this->get('/investidor/negocios/'.$businessId)->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/business')
|
||||
->where('record.modality', $case['modality'])
|
||||
->has('formSchema')
|
||||
->where('objectKinds', fn ($kinds) => $kinds->contains($case['kind'])));
|
||||
|
||||
$objectId = $this->postJson($this->base.'/'.$businessId.'/objects', [
|
||||
'kind' => $case['kind'],
|
||||
'version_no' => 1,
|
||||
'reason' => 'Synthetic subject record for QA',
|
||||
'payload' => ['label' => $case['label'], 'source_reference' => 'Synthetic source reference'],
|
||||
])->assertCreated()->assertJsonPath('verification_status', 'pending')->json('id');
|
||||
|
||||
$this->getJson($this->base.'/'.$businessId)->assertOk()
|
||||
->assertJsonPath('record.modality', $case['modality'])
|
||||
->assertJsonPath('objects.0.id', $objectId)
|
||||
->assertJsonPath('objects.0.kind', $case['kind'])
|
||||
->assertJsonPath('objects.0.verification_status', 'pending');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,19 @@ class ExistingBusinessWizardTest extends TestCase
|
||||
$this->assertStringNotContainsString('synthetic@example.test', $raw);
|
||||
}
|
||||
|
||||
public function test_company_purchase_is_a_distinct_existing_business_modality(): void
|
||||
{
|
||||
config(['existing-business.enabled' => true]);
|
||||
$owner = User::factory()->create();
|
||||
$this->actingAs($owner)->postJson('/api/v1/existing-business/listings', [
|
||||
'modality' => 'company_purchase', 'classification' => 'confidential', 'reason' => 'Prepare a company acquisition listing',
|
||||
'payload' => ['title' => 'Private company acquisition search', 'wizard_version' => '1', 'wizard_step' => '1'],
|
||||
])->assertCreated()->assertJsonPath('modality', 'company_purchase');
|
||||
$this->assertDatabaseHas('existing_businesses', ['owner_user_id' => $owner->id, 'modality' => 'company_purchase', 'status' => 'draft']);
|
||||
$this->get('/negocios?modality=company_purchase')->assertOk()
|
||||
->assertInertia(fn ($page) => $page->where('filters.modality', 'company_purchase')->has('results.data', 0));
|
||||
}
|
||||
|
||||
public function test_multiple_locations_require_distinct_public_paths_from_the_same_hierarchy(): void
|
||||
{
|
||||
config(['existing-business.enabled' => true]);
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\ScanDocumentForMalware;
|
||||
use App\Console\Commands\ImportDocumentBatch;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ImportDocumentBatchTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private string $staging;
|
||||
|
||||
private string $batchName;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->batchName = 'test-'.\Illuminate\Support\Str::uuid();
|
||||
$this->staging = storage_path('app/private/document-import-staging/'.$this->batchName);
|
||||
File::ensureDirectoryExists($this->staging);
|
||||
Storage::fake('local');
|
||||
Bus::fake();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
File::deleteDirectory($this->staging);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_preview_is_read_only_and_batch_import_is_private_idempotent_and_attributed(): void
|
||||
{
|
||||
$pdf = "%PDF-1.4\nfixture document\n%%EOF";
|
||||
file_put_contents($this->staging.'/source.pdf', $pdf);
|
||||
$record = [
|
||||
'external_id' => 'test-document-v1', 'relative_path' => $this->batchName.'/source.pdf',
|
||||
'title' => 'Documento de teste', 'issuer' => 'Entidade de teste', 'file_name' => 'documento.pdf',
|
||||
'source_url' => 'https://example.test/documento.pdf', 'source_reference' => 'URL de teste; sem validação legal.',
|
||||
'document_number' => 'TEST-1', 'document_date' => '2026-01-01', 'language' => 'pt',
|
||||
'version_label' => 'edição de teste', 'category' => 'general', 'topic' => 'test', 'document_type' => 'guide',
|
||||
];
|
||||
file_put_contents($this->staging.'/manifest.json', json_encode(['documents' => [$record, $record]], JSON_THROW_ON_ERROR));
|
||||
$actor = \App\Models\User::factory()->create();
|
||||
|
||||
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json'])->assertSuccessful();
|
||||
$this->assertDatabaseCount('documents', 0);
|
||||
$this->assertDatabaseCount('portal_resources', 0);
|
||||
$this->assertSame([], Storage::disk('local')->allFiles('portal-documents'));
|
||||
|
||||
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json', '--apply' => true, '--actor' => (string) $actor->id])->assertSuccessful();
|
||||
$this->assertDatabaseCount('documents', 1);
|
||||
$this->assertDatabaseCount('portal_resources', 1);
|
||||
$document = DB::table('documents')->firstOrFail();
|
||||
$this->assertSame($actor->id, $document->uploaded_by);
|
||||
$this->assertSame('quarantined', $document->status);
|
||||
$this->assertSame('internal', $document->data_classification);
|
||||
$this->assertSame('pending', $document->malware_scan_status);
|
||||
$this->assertDatabaseHas('portal_resources', ['published' => false, 'rights_status' => 'unconfirmed', 'created_by' => $actor->id]);
|
||||
$this->assertDatabaseHas('audit_events', ['actor_user_id' => $actor->id, 'action' => 'private_document_batch_imported']);
|
||||
Bus::assertDispatchedTimes(ScanDocumentForMalware::class, 1);
|
||||
|
||||
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json', '--apply' => true, '--actor' => (string) $actor->id])->assertSuccessful();
|
||||
$this->assertDatabaseCount('documents', 1);
|
||||
$this->assertDatabaseCount('portal_resources', 1);
|
||||
$this->assertDatabaseCount('audit_events', 1);
|
||||
Bus::assertDispatchedTimes(ScanDocumentForMalware::class, 1);
|
||||
}
|
||||
|
||||
public function test_apply_refuses_missing_actor_and_source_path_traversal(): void
|
||||
{
|
||||
file_put_contents($this->staging.'/source.pdf', "%PDF-1.4\nfixture\n%%EOF");
|
||||
$record = ['external_id' => 'test-document', 'relative_path' => '..\\..\\..\\..\\.env', 'title' => 'Test', 'issuer' => 'Test'];
|
||||
file_put_contents($this->staging.'/manifest.json', json_encode(['documents' => [$record]], JSON_THROW_ON_ERROR));
|
||||
|
||||
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json', '--apply' => true])->assertFailed();
|
||||
$this->assertDatabaseCount('documents', 0);
|
||||
|
||||
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json'])->assertFailed();
|
||||
$this->assertDatabaseCount('documents', 0);
|
||||
}
|
||||
}
|
||||
@@ -54,9 +54,10 @@ class ImportLegalSourceArchiveTest extends TestCase
|
||||
$this->assertDatabaseCount('documents', $expectedResources);
|
||||
$this->assertDatabaseCount('portal_resources', $expectedResources);
|
||||
$this->assertDatabaseCount('portal_resource_links', 19);
|
||||
$this->assertDatabaseCount('portal_resource_links', 8, ['target_type' => 'requirement']);
|
||||
$this->assertSame(8, DB::table('portal_resource_links')->where('target_type', 'requirement')->count());
|
||||
$this->assertDatabaseCount('portal_resource_revisions', $expectedResources);
|
||||
$this->assertCount($expectedResources, Storage::disk('local')->allFiles('portal-documents'));
|
||||
|
||||
$this->assertSame($expectedResources, DB::table('documents')->where('source_system', 'legal-source-archive')
|
||||
->where('status', 'active')->where('data_classification', 'internal')->where('rights_status', 'unconfirmed')
|
||||
->where('malware_scan_status', 'clean')->whereColumn('sha256', 'malware_scanned_sha256')->count());
|
||||
@@ -93,8 +94,17 @@ class ImportLegalSourceArchiveTest extends TestCase
|
||||
$this->assertDatabaseCount('documents', $expectedResources);
|
||||
$this->assertDatabaseCount('portal_resources', $expectedResources);
|
||||
$this->assertDatabaseCount('portal_resource_links', 19);
|
||||
$this->assertDatabaseCount('portal_resource_links', 8, ['target_type' => 'requirement']);
|
||||
$this->assertSame(8, DB::table('portal_resource_links')->where('target_type', 'requirement')->count());
|
||||
$this->assertDatabaseCount('portal_resource_revisions', $expectedResources);
|
||||
$this->assertCount($expectedResources, Storage::disk('local')->allFiles('portal-documents'));
|
||||
|
||||
$br248 = DB::table('portal_resources')->where('document_number', 'BR n.º 248/2025, Suplemento n.º 1')->firstOrFail();
|
||||
DB::table('portal_resource_links')->where('resource_id', $br248->id)->where('target_type', 'requirement')
|
||||
->where('target_key', 'fiscal.irpc.lei_12_2025')->delete();
|
||||
$this->artisan('documents:import-legal-source-archive', ['--apply' => true])->assertSuccessful();
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $br248->id, 'target_type' => 'requirement',
|
||||
'target_key' => 'fiscal.irpc.lei_12_2025', 'review_status' => 'confirmed']);
|
||||
$this->assertDatabaseCount('portal_resource_links', 19);
|
||||
$this->assertDatabaseCount('portal_resource_revisions', $expectedResources + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,40 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$this->assertNotContains($national->id, $service->query([])->pluck('id')->all());
|
||||
}
|
||||
|
||||
public function test_opportunity_cluster_and_corridor_filters_use_their_public_opportunity_relations(): void
|
||||
{
|
||||
$country = $this->location('country');
|
||||
$province = $this->location('province', $country);
|
||||
$otherProvince = $this->location('province', $country);
|
||||
foreach ([$country, $province, $otherProvince] as $territoryId) {
|
||||
DB::table('geo_locations')->where('id', $territoryId)->update(['source_system' => 'cartografia-workbook',
|
||||
'external_id' => '964a187ad32ea553b9e112cd159caa90b900050c42b7329594a75bcd798a96ff:'.$territoryId,
|
||||
'data_classification' => 'public']);
|
||||
}
|
||||
$sector = Sector::create(['name' => 'Public relation test', 'slug' => 'public-relation-test', 'is_active' => true]);
|
||||
$corridorId = (string) Str::uuid();
|
||||
DB::table('development_corridors')->insert(['id' => $corridorId, 'code' => 'QA-CORRIDOR', 'name' => 'QA public corridor',
|
||||
'status' => 'active', 'data_classification' => 'public', 'created_at' => now(), 'updated_at' => now()]);
|
||||
$clusterId = (string) Str::uuid();
|
||||
DB::table('economic_clusters')->insert(['id' => $clusterId, 'code' => 'QA-CLUSTER', 'name' => 'QA public cluster',
|
||||
'sector' => 'QA', 'status' => 'active', 'data_classification' => 'public', 'created_at' => now(), 'updated_at' => now()]);
|
||||
$opportunity = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'QA-CORRIDOR-OPP', 'slug' => 'qa-corridor-opp',
|
||||
'title' => 'QA opportunity linked to corridor', 'status' => 'published', 'published_at' => now()->subMinute(), 'primary_territory_id' => $province]);
|
||||
DB::table('opportunity_corridors')->insert(['opportunity_id' => $opportunity->id, 'corridor_id' => $corridorId]);
|
||||
DB::table('opportunity_clusters')->insert(['opportunity_id' => $opportunity->id, 'cluster_id' => $clusterId]);
|
||||
|
||||
$this->getJson('/api/v1/investment/references')->assertOk()->assertJsonFragment(['id' => $corridorId, 'name' => 'QA public corridor'])
|
||||
->assertJsonFragment(['id' => $clusterId, 'name' => 'QA public cluster']);
|
||||
$this->getJson('/api/v1/investment/search?dimension=corridor&province_id='.$province)->assertOk()
|
||||
->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $opportunity->id);
|
||||
$this->getJson('/api/v1/investment/search?corridor_id='.$corridorId.'&province_id='.$province)->assertOk()
|
||||
->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $opportunity->id);
|
||||
$this->getJson('/api/v1/investment/search?cluster_id='.$clusterId)->assertOk()
|
||||
->assertJsonPath('total', 1)->assertJsonPath('data.0.id', $opportunity->id);
|
||||
$this->getJson('/api/v1/investment/search?dimension=corridor&province_id='.$otherProvince)->assertOk()
|
||||
->assertJsonPath('total', 0)->assertJsonCount(0, 'data');
|
||||
}
|
||||
|
||||
public function test_cluster_territory_uses_only_public_validated_project_links_and_project_locations(): void
|
||||
{
|
||||
$country = $this->location('country');
|
||||
|
||||
@@ -44,7 +44,7 @@ class InvestmentZoneTest extends TestCase
|
||||
$this->getJson('/api/v2/investment/zones')->assertJsonPath('records.total', 0);
|
||||
$this->postJson($url.'/'.$id, [...$payload, '_method' => 'PUT', 'version_no' => 1, 'name' => 'Changed synthetic zone'])->assertOk()->assertJsonPath('version_no', 2);
|
||||
$this->putJson($url.'/'.$id, [...$payload, 'version_no' => 1])->assertConflict();
|
||||
$this->postJson($url.'/'.$id.'/publish', ['version_no' => 2])->assertForbidden();
|
||||
$this->postJson($url.'/'.$id.'/publish', ['version_no' => 2])->assertUnprocessable();
|
||||
$this->actingAs($this->manager())->postJson($url.'/'.$id.'/publish', ['version_no' => 2])->assertUnprocessable();
|
||||
$this->assertDatabaseCount('investment_zone_revisions', 2);
|
||||
$snapshot = DB::table('investment_zone_revisions')->where('zone_id', $id)->where('version_no', 1)->value('snapshot');
|
||||
@@ -123,8 +123,7 @@ class InvestmentZoneTest extends TestCase
|
||||
public function test_documented_general_industrial_park_can_publish_without_special_regime_or_operator_and_filters_match_csv(): void
|
||||
{
|
||||
$editor = $this->manager();
|
||||
$publisher = $this->manager();
|
||||
config(['investment-zones.publishers' => [$publisher->email]]);
|
||||
config(['investment-zones.publishers' => []]);
|
||||
$country = $this->geoNode('country', 'Synthetic country for park', null);
|
||||
$province = $this->geoNode('province', 'Synthetic province for park', $country);
|
||||
$evidence = [['title' => 'Synthetic municipal project page', 'url' => 'https://example.test/munhava', 'source_type' => 'institutional',
|
||||
@@ -136,7 +135,7 @@ class InvestmentZoneTest extends TestCase
|
||||
'source_evidence' => $evidence, 'area_components' => [['type' => 'pilot', 'value' => 50, 'unit' => 'ha', 'status' => 'reported',
|
||||
'source_reference' => 'Synthetic source reports pilot area; not available land.', 'source_date' => null]],
|
||||
])->assertCreated()->json('id');
|
||||
$this->actingAs($publisher)->postJson('/api/v2/investment/admin/zones/'.$id.'/publish', ['version_no' => 1])->assertOk();
|
||||
$this->actingAs($editor)->postJson('/api/v2/investment/admin/zones/'.$id.'/publish', ['version_no' => 1])->assertOk();
|
||||
$this->getJson('/api/v2/investment/zones?development_status=planned')->assertOk()->assertJsonPath('records.total', 1)
|
||||
->assertJsonPath('records.data.0.id', $id)->assertJsonPath('records.data.0.availability_status', 'not_informed');
|
||||
$csv = $this->get('/api/v2/investment/zones/export.csv?development_status=planned')->assertOk()->assertHeader('content-type', 'text/csv; charset=UTF-8');
|
||||
@@ -148,6 +147,55 @@ class InvestmentZoneTest extends TestCase
|
||||
$this->assertDatabaseHas('investment_zones', ['id' => $id, 'operator_id' => null, 'legal_source_id' => null, 'publication_status' => 'published']);
|
||||
}
|
||||
|
||||
public function test_promoter_sourced_industrial_park_can_be_published_as_informational_only(): void
|
||||
{
|
||||
$manager = $this->manager();
|
||||
config(['investment-zones.publishers' => []]);
|
||||
$country = $this->geoNode('country', 'Synthetic country for promoter park', null);
|
||||
$province = $this->geoNode('province', 'Synthetic province for promoter park', $country);
|
||||
$id = $this->actingAs($manager)->postJson('/api/v2/investment/admin/zones', [
|
||||
'code' => 'QA-PROMOTER-PARK', 'name' => 'Synthetic promoter-sourced park', 'category' => 'industrial_park',
|
||||
'physical_category' => 'industrial_park', 'legal_regime' => 'pending', 'development_status' => 'in_development',
|
||||
'availability_status' => 'not_informed',
|
||||
'description' => 'Informational project record; legal status, operations, incentives and available land are not confirmed.',
|
||||
'province_id' => $province,
|
||||
'source_evidence' => [['title' => 'Promoter project page', 'url' => 'https://example.test/promoter-park', 'source_type' => 'promoter',
|
||||
'supports' => 'The promoter identifies the project and province; no legal designation or land availability claim.', 'source_date' => null]],
|
||||
])->assertCreated()->json('id');
|
||||
|
||||
$this->postJson('/api/v2/investment/admin/zones/'.$id.'/publish', ['version_no' => 1])->assertOk();
|
||||
$this->getJson('/api/v2/investment/zones?category=industrial_park')->assertOk()
|
||||
->assertJsonPath('records.total', 1)->assertJsonPath('records.data.0.id', $id)
|
||||
->assertJsonPath('records.data.0.legal_regime', 'pending')
|
||||
->assertJsonPath('records.data.0.availability_status', 'not_informed')
|
||||
->assertJsonPath('records.data.0.source_evidence.0.source_type', 'promoter');
|
||||
$this->assertDatabaseHas('investment_zones', ['id' => $id, 'publication_status' => 'published', 'legal_regime' => 'pending',
|
||||
'operator_id' => null, 'legal_source_id' => null]);
|
||||
}
|
||||
|
||||
public function test_officially_sourced_zee_can_be_published_informationally_by_the_authenticated_author(): void
|
||||
{
|
||||
$manager = $this->manager();
|
||||
config(['investment-zones.publishers' => []]);
|
||||
$country = $this->geoNode('country', 'Synthetic country for ZEE', null);
|
||||
$province = $this->geoNode('province', 'Synthetic province for ZEE', $country);
|
||||
$id = $this->actingAs($manager)->postJson('/api/v2/investment/admin/zones', [
|
||||
'code' => 'QA-INFO-ZEE', 'name' => 'Synthetic reported ZEE', 'category' => 'zee',
|
||||
'physical_category' => 'economic_zone', 'legal_regime' => 'zee',
|
||||
'description' => 'Informational record; legal status and incentives remain unconfirmed.', 'province_id' => $province,
|
||||
'source_evidence' => [['title' => 'Institutional source', 'url' => 'https://example.test/zee', 'source_type' => 'institutional',
|
||||
'supports' => 'Reports the zone identity and province; does not confirm current legal status or incentives.', 'source_date' => null]],
|
||||
])->assertCreated()->json('id');
|
||||
|
||||
$this->postJson('/api/v2/investment/admin/zones/'.$id.'/publish', ['version_no' => 1])->assertOk();
|
||||
$this->getJson('/api/v2/investment/zones?category=zee')->assertOk()->assertJsonPath('records.total', 1)
|
||||
->assertJsonPath('records.data.0.id', $id);
|
||||
$this->get('/oportunidades?province_id='.$province)->assertOk()
|
||||
->assertInertia(fn ($page) => $page->has('references.zones', 1)->where('references.zones.0.id', $id));
|
||||
$this->assertDatabaseHas('investment_zones', ['id' => $id, 'editor_id' => $manager->id, 'reviewer_id' => $manager->id,
|
||||
'publication_status' => 'published', 'operator_id' => null, 'legal_source_id' => null]);
|
||||
}
|
||||
|
||||
public function test_zone_record_separates_physical_type_and_legal_regime_and_searches_multiple_reviewed_territories_once(): void
|
||||
{
|
||||
$editor = $this->manager();
|
||||
@@ -280,9 +328,11 @@ class InvestmentZoneTest extends TestCase
|
||||
$organization = (string) Str::uuid();
|
||||
DB::table('organizations')->insert(['id' => $organization, 'name' => 'Synthetic operator', 'organization_type' => 'private']);
|
||||
$sector = Sector::create(['slug' => 'qa-zone-sector', 'name' => 'Synthetic sector', 'is_active' => true]);
|
||||
$opportunity = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'QA-ZONE', 'slug' => 'qa-zone', 'title' => 'Synthetic investment', 'status' => 'published', 'published_at' => now()->subMinute()]);
|
||||
$zoneCountry = $this->geoNode('country', 'Synthetic Country for zone link', null);
|
||||
$zoneProvince = $this->geoNode('province', 'Synthetic Province for zone link', $zoneCountry);
|
||||
$opportunity = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'QA-ZONE', 'slug' => 'qa-zone', 'title' => 'Synthetic investment',
|
||||
'status' => 'published', 'published_at' => now()->subMinute(), 'province' => 'Synthetic Province for zone link',
|
||||
'geography_scope' => 'specific', 'primary_territory_id' => $zoneProvince]);
|
||||
$zoneIds = [];
|
||||
foreach (['zee', 'zfi'] as $category) {
|
||||
$this->actingAs($editor);
|
||||
@@ -313,6 +363,11 @@ class InvestmentZoneTest extends TestCase
|
||||
$this->getJson('/api/v1/investment/search?dimension=zfi&view=list')->assertOk()->assertJsonPath('total', 1);
|
||||
$this->getJson('/api/v1/investment/search?dimension=zee&q=not-present')->assertJsonPath('total', 0);
|
||||
$this->getJson('/api/v1/investment/search?dimension=invalid')->assertUnprocessable();
|
||||
$this->get('/oportunidades?province_id='.$zoneProvince.'&zee_id='.$zoneIds['zee_id'])->assertOk()
|
||||
->assertInertia(fn ($page) => $page->component('investment/catalogue')->has('references.zones', 2)
|
||||
->has('results.data', 1)->where('results.data.0.id', $opportunity->id));
|
||||
$this->getJson('/api/v2/investment/zones/'.$zoneIds['zee_id'])->assertOk()
|
||||
->assertJsonPath('opportunities.total', 1)->assertJsonPath('opportunities.data.0.id', $opportunity->id);
|
||||
$this->getJson('/api/v2/investment/zones')->assertJsonPath('records.total', 2)->assertJsonMissingPath('records.data.0.editor_id');
|
||||
$this->getJson('/api/v2/investment/zone-map')->assertJsonCount(2, 'features');
|
||||
$this->seed(InvestmentReferenceSeeder::class);
|
||||
@@ -382,7 +437,8 @@ class InvestmentZoneTest extends TestCase
|
||||
$this->assertDatabaseCount('investment_zone_relations', 3);
|
||||
$this->assertDatabaseCount('investment_items', 0);
|
||||
config(['investment-zones.publishers' => [], 'investment-zones.legal_reviewers' => [], 'investment-zones.gis_reviewers' => []]);
|
||||
$this->postJson('/api/v2/investment/admin/zones/'.$id.'/publish', ['version_no' => 1])->assertForbidden();
|
||||
$this->postJson('/api/v2/investment/admin/zones/'.$id.'/publish', ['version_no' => 1])->assertUnprocessable();
|
||||
$this->assertDatabaseHas('investment_zones', ['id' => $id, 'publication_status' => 'draft']);
|
||||
$this->getJson('/api/v2/investment/zones')->assertJsonPath('records.total', 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,28 @@ class PortalServicesTest extends TestCase
|
||||
$this->get('/management/portal-services')->assertRedirect('/login');
|
||||
}
|
||||
|
||||
public function test_document_management_writes_redirect_to_the_management_get_route(): void
|
||||
{
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager);
|
||||
|
||||
// A stale Referer can point at the write-only resource endpoint. Both
|
||||
// validation failures and successful writes must finish at a real GET.
|
||||
$this->from('/management/portal-services/resources/4')
|
||||
->post('/management/portal-services/resources/4', ['published' => 'invalid'])
|
||||
->assertRedirect(route('services.manage'))
|
||||
->assertSessionHasErrors('published');
|
||||
$this->get(route('services.manage'))->assertOk()->assertInertia(fn (Assert $page) => $page->component('portal/manage'));
|
||||
|
||||
$this->from('/management/portal-services/resources/4')
|
||||
->post('/management/portal-services/resources', [])
|
||||
->assertRedirect(route('services.manage'))
|
||||
->assertSessionHasErrors('document_id');
|
||||
|
||||
$this->get('/management/portal-services/resources/4')->assertStatus(405);
|
||||
}
|
||||
|
||||
public function test_support_receipt_is_idempotent_private_and_requires_consent(): void
|
||||
{
|
||||
$owner = User::factory()->create();
|
||||
@@ -110,19 +132,21 @@ class PortalServicesTest extends TestCase
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 0));
|
||||
$id = $this->registerDocumentResource($document->id, 'Guia de teste');
|
||||
$this->assertDatabaseHas('portal_resources', ['id' => $id, 'published' => false, 'rights_status' => 'authorized']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertUnprocessable();
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertRedirect(route('services.manage'))->assertSessionHasErrors('published');
|
||||
// A malware scan releases technical quarantine without changing privacy or editorial publication.
|
||||
DB::table('documents')->where('id', $document->id)->update(['status' => 'active', 'data_classification' => 'public']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertSessionHasNoErrors();
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertRedirect(route('services.manage'))->assertSessionHasNoErrors();
|
||||
$this->get('/documentos/'.$id.'/download')->assertOk()->assertDownload('exemplo.txt');
|
||||
$this->get('/documentos/'.$id.'?back=%2Fdocumentos%3Ftopic%3DInvestimento')->assertInertia(fn (Assert $page) => $page
|
||||
->component('portal/document')->where('resource.title', 'Guia de teste')->where('backUrl', '/documentos?topic=Investimento')
|
||||
->has('resource.links', 3)->missing('resource.storage_key')->missing('resource.sha256'));
|
||||
$this->get('/')->assertInertia(fn (Assert $page) => $page->has('essentialResources', 1));
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 1)->where('resources.data.0.title', 'Guia de teste')->missing('resources.data.0.storage_key'));
|
||||
$this->get('/documentos?q=Guia%20de%20teste&document_type=guide')->assertInertia(fn (Assert $page) => $page
|
||||
->component('portal/services')->has('resources.data', 1)->where('resources.data.0.title', 'Guia de teste'));
|
||||
$this->getJson('/api/v1/documents/recommendations?module=simulator&activity_id=CAE-TEST&stage=review')->assertOk()->assertJsonPath('data.0.title', 'Guia de teste');
|
||||
$this->put('/management/portal-services/resources/'.$id, [...$this->documentResourcePayload($document->id, 'Guia de teste revisto'), 'metadata_version' => 2, 'description' => 'Resumo editado pelo gestor.'])
|
||||
->assertSessionHasNoErrors();
|
||||
->assertRedirect(route('services.manage'))->assertSessionHasNoErrors();
|
||||
$this->assertDatabaseHas('portal_resources', ['id' => $id, 'published' => true, 'title' => 'Guia de teste revisto']);
|
||||
$this->assertDatabaseHas('portal_resource_revisions', ['resource_id' => $id, 'revision_no' => 3, 'change_type' => 'metadata_updated']);
|
||||
DB::table('documents')->where('id', $document->id)->update(['data_classification' => 'internal']);
|
||||
@@ -175,7 +199,7 @@ class PortalServicesTest extends TestCase
|
||||
$this->assertDatabaseCount('portal_resource_links', 20);
|
||||
}
|
||||
|
||||
public function test_document_publication_marks_proposals_and_requires_a_confirmed_source(): void
|
||||
public function test_legislation_with_an_identified_source_can_be_published_for_consultation_without_claiming_confirmation(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$manager = User::factory()->create();
|
||||
@@ -187,12 +211,77 @@ class PortalServicesTest extends TestCase
|
||||
$this->post('/management/portal-services/resources', $payload)->assertSessionHasNoErrors();
|
||||
$id = (int) DB::table('portal_resources')->value('id');
|
||||
DB::table('documents')->where('id', $document->id)->update(['status' => 'active', 'data_classification' => 'public']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertUnprocessable();
|
||||
$this->put('/management/portal-services/resources/'.$id, [...$payload, 'metadata_version' => 1, 'source_confirmation' => 'official_confirmed'])
|
||||
->assertSessionHasNoErrors();
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertSessionHasNoErrors();
|
||||
$this->get('/legislacao')->assertInertia(fn (Assert $page) => $page->where('resources.data.0.legal_status', 'proposed')
|
||||
->where('resources.data.0.source_confirmation', 'official_confirmed'));
|
||||
->where('resources.data.0.source_confirmation', 'identified'));
|
||||
}
|
||||
|
||||
public function test_recorded_user_authorization_publishes_only_eligible_document_scope_in_one_manager_action(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->post('/management/portal-services/disclosure-authorization/apply')->assertRedirect('/login');
|
||||
$this->actingAs($manager);
|
||||
|
||||
$resourceIds = [];
|
||||
$titles = [
|
||||
1 => 'Lei n.º 22/2022, de 28 de Dezembro — alteração ao Código do IVA (republicação)',
|
||||
2 => 'Boletim da República n.º 248/2025 — Suplemento n.º 1',
|
||||
3 => 'Boletim da República n.º 89, I Série (08-06-2017) — aviso de rectificação da Lei n.º 13/2016',
|
||||
4 => 'Codificador da Divisão Político-Administrativa (INE, 07-06-2012)',
|
||||
];
|
||||
foreach ([1, 2, 3, 4] as $number) {
|
||||
$this->post('/management/portal-services/upload', [
|
||||
'file' => UploadedFile::fake()->createWithContent("reference-$number.pdf", "document bytes $number"),
|
||||
'original_source' => 'https://example.gov.mz/reference',
|
||||
])->assertSessionHasNoErrors();
|
||||
$document = DB::table('documents')->where('file_name', "reference-$number.pdf")->firstOrFail();
|
||||
$resourceIds[] = $this->registerDocumentResource($document->id, $titles[$number], [
|
||||
'document_type' => $number === 3 ? 'legislation' : 'reference_data',
|
||||
'legislation' => $number === 3,
|
||||
'source_confirmation' => $number === 3 ? 'identified' : 'official_confirmed',
|
||||
'legal_status' => $number === 3 ? 'unknown' : 'historical',
|
||||
'rights_status' => 'unconfirmed', 'data_classification' => 'internal',
|
||||
]);
|
||||
DB::table('documents')->where('id', $document->id)->update([
|
||||
'status' => 'active', 'malware_scan_status' => 'clean', 'malware_scanned_sha256' => $document->sha256,
|
||||
]);
|
||||
}
|
||||
$this->assertCount(4, $resourceIds);
|
||||
DB::table('audit_events')->insert([
|
||||
'source_system' => 'user-instruction', 'external_id' => 'document-repository-disclosure-authorization-2026-10-06-v1',
|
||||
'data_classification' => 'internal', 'entity_type' => 'portal_document_repository', 'entity_id' => null,
|
||||
'action' => 'public_disclosure_authorized', 'actor_user_id' => null,
|
||||
'after_data' => json_encode(['resource_ids' => $resourceIds], JSON_THROW_ON_ERROR),
|
||||
]);
|
||||
|
||||
$this->post('/management/portal-services/disclosure-authorization/apply')
|
||||
->assertRedirect(route('services.manage'))->assertSessionHasNoErrors();
|
||||
$this->assertDatabaseCount('portal_resource_revisions', 8);
|
||||
$this->assertDatabaseCount('audit_events', 13);
|
||||
$this->assertSame(4, DB::table('portal_resources')->where('published', true)->count());
|
||||
$this->assertSame(4, DB::table('documents')->where('data_classification', 'public')->where('rights_status', 'authorized')->count());
|
||||
$this->assertDatabaseHas('portal_resources', ['id' => $resourceIds[2], 'published' => true, 'source_confirmation' => 'identified', 'legal_status' => 'unknown']);
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[0], 'target_type' => 'requirement',
|
||||
'target_key' => 'fiscal.iva.lei_22_2022', 'review_status' => 'confirmed', 'applicability' => 'evidence']);
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[1], 'target_type' => 'requirement',
|
||||
'target_key' => 'fiscal.iva.lei_10_2025', 'review_status' => 'pending', 'applicability' => 'evidence']);
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[2], 'target_type' => 'requirement',
|
||||
'target_key' => 'fiscal.iva.lei_13_2016_rectification_2017', 'review_status' => 'pending', 'applicability' => 'evidence']);
|
||||
$this->assertDatabaseHas('audit_events', ['source_system' => 'portal-services', 'entity_type' => 'portal_resources',
|
||||
'actor_user_id' => $manager->id, 'action' => 'published_under_user_authorization']);
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 4));
|
||||
$this->get('/documentos?q=22%2F2022')->assertInertia(fn (Assert $page) => $page
|
||||
->has('resources.data', 1)->where('resources.data.0.id', $resourceIds[0]));
|
||||
$this->get('/documentos?category=Guia&document_type=legislation')->assertInertia(fn (Assert $page) => $page
|
||||
->has('resources.data', 1)->where('resources.data.0.id', $resourceIds[2]));
|
||||
$this->get('/documentos/'.$resourceIds[2])->assertInertia(fn (Assert $page) => $page->component('portal/document')
|
||||
->where('resource.source_confirmation', 'identified')->where('resource.legal_status', 'unknown'));
|
||||
$this->get('/documentos/'.$resourceIds[0].'/download')->assertOk()->assertDownload('reference-1.pdf');
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[0], 'target_type' => 'module', 'target_key' => 'simulator']);
|
||||
$this->post('/management/portal-services/disclosure-authorization/apply')->assertSessionHasNoErrors();
|
||||
$this->assertDatabaseCount('portal_resource_revisions', 8);
|
||||
}
|
||||
|
||||
public function test_manager_classifies_a_reviewed_document_public_before_separate_publication(): void
|
||||
@@ -286,7 +375,7 @@ class PortalServicesTest extends TestCase
|
||||
$resource = DB::table('portal_resources')->firstOrFail();
|
||||
$this->assertFalse((bool) $resource->published);
|
||||
$this->assertSame('internal', DB::table('documents')->where('id', $document->id)->value('data_classification'));
|
||||
$this->post('/management/portal-services/resources/'.$resource->id, ['published' => true])->assertUnprocessable();
|
||||
$this->post('/management/portal-services/resources/'.$resource->id, ['published' => true])->assertRedirect(route('services.manage'))->assertSessionHasErrors('published');
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 0));
|
||||
$this->get('/documentos/'.$resource->id)->assertNotFound();
|
||||
$this->get('/documentos/'.$resource->id.'/download')->assertNotFound();
|
||||
@@ -347,6 +436,31 @@ class PortalServicesTest extends TestCase
|
||||
$this->assertDatabaseCount('documents', 1);
|
||||
}
|
||||
|
||||
public function test_public_recommendations_return_only_confirmed_requirement_citations(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->post('/management/portal-services/upload', [
|
||||
'file' => UploadedFile::fake()->createWithContent('public-evidence.txt', 'Documentary evidence fixture.'),
|
||||
])->assertSessionHasNoErrors();
|
||||
$document = DB::table('documents')->firstOrFail();
|
||||
$payload = $this->documentResourcePayload($document->id, 'Fontes fiscais QA');
|
||||
$payload['associations'][] = ['target_type' => 'requirement', 'target_key' => 'fiscal.iva.lei_22_2022', 'relationship' => 'cites',
|
||||
'applicability' => 'evidence', 'review_status' => 'confirmed', 'basis_reference' => 'Citação fixture, artigo 17(1), página 3.'];
|
||||
$payload['associations'][] = ['target_type' => 'requirement', 'target_key' => 'fiscal.iva.lei_10_2025', 'relationship' => 'cites',
|
||||
'applicability' => 'evidence', 'review_status' => 'pending', 'basis_reference' => 'Citação ainda não conferida no fixture.'];
|
||||
$this->post('/management/portal-services/resources', $payload)->assertSessionHasNoErrors();
|
||||
$id = (int) DB::table('portal_resources')->where('title', 'Fontes fiscais QA')->value('id');
|
||||
DB::table('documents')->where('id', $document->id)->update(['status' => 'active', 'data_classification' => 'public']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertSessionHasNoErrors();
|
||||
|
||||
$this->getJson('/api/v1/documents/recommendations?module=simulator')->assertOk()
|
||||
->assertJsonPath('data.0.documentary_evidence.0.key', 'fiscal.iva.lei_22_2022')
|
||||
->assertJsonPath('data.0.documentary_evidence.0.status', 'citation_checked_application_pending')
|
||||
->assertJsonMissing(['key' => 'fiscal.iva.lei_10_2025']);
|
||||
}
|
||||
|
||||
private function registerDocumentResource(string $documentId, string $title, array $overrides = []): int
|
||||
{
|
||||
$payload = [...$this->documentResourcePayload($documentId, $title), ...$overrides];
|
||||
|
||||
Reference in New Issue
Block a user