varias alteracoes
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-06 14:50:12 +02:00
parent 4f35313d06
commit e65cb26901
333 changed files with 54656 additions and 2058 deletions
+175 -2
View File
@@ -25,7 +25,7 @@ class InvestmentZoneTest extends TestCase
$user = User::factory()->create();
$user->forceFill(['two_factor_secret' => Crypt::encryptString('SYNTHETIC'), 'two_factor_confirmed_at' => now()])->save();
config(['portal.managers' => [...config('portal.managers', []), $user->email]]);
foreach (['legal_reviewers', 'gis_reviewers', 'publishers'] as $role) {
foreach (['legal_reviewers', 'gis_reviewers', 'territory_reviewers', 'publishers'] as $role) {
config(['investment-zones.'.$role => [...config('investment-zones.'.$role, []), $user->email]]);
}
@@ -72,16 +72,40 @@ class InvestmentZoneTest extends TestCase
$geometryMigration = require database_path('migrations/2026_09_28_110000_zone_geometry_review.php');
$businessMigration = require database_path('migrations/2026_09_28_130000_existing_business_foundation.php');
$intakeMigration = require database_path('migrations/2026_09_28_140000_existing_business_intake.php');
$marketplaceMigration = require database_path('migrations/2026_09_30_120000_extend_existing_business_marketplace.php');
$taxGovernanceMigration = require database_path('migrations/2026_10_03_170000_create_simulation_tax_rule_governance.php');
$draftContinuityMigration = require database_path('migrations/2026_10_04_120000_add_simulation_draft_continuity.php');
$zoneExtensionMigration = require database_path('migrations/2026_10_04_130000_extend_investment_zone_records.php');
$zoneAttachmentsMigration = require database_path('migrations/2026_10_04_140000_create_investment_zone_attachments.php');
$zonePublicationMigration = require database_path('migrations/2026_10_04_150000_relax_zone_operator_publication_requirement.php');
$zoneDevelopmentMigration = require database_path('migrations/2026_10_04_160000_extend_zone_development_and_area_scopes.php');
$primaryTerritoryMigration = require database_path('migrations/2026_09_28_160000_investment_primary_territory.php');
$zoneDevelopmentMigration->down();
$zonePublicationMigration->down();
$zoneAttachmentsMigration->down();
$zoneExtensionMigration->down();
$draftContinuityMigration->down();
$taxGovernanceMigration->down();
$marketplaceMigration->down();
$intakeMigration->down();
$businessMigration->down();
$originMigration->down();
$geometryMigration->down();
$primaryTerritoryMigration->down();
$migration->down();
$migration->up();
$taxGovernanceMigration->up();
$geometryMigration->up();
$originMigration->up();
$businessMigration->up();
$intakeMigration->up();
$marketplaceMigration->up();
$primaryTerritoryMigration->up();
$zoneExtensionMigration->up();
$zoneAttachmentsMigration->up();
$zonePublicationMigration->up();
$zoneDevelopmentMigration->up();
$draftContinuityMigration->up();
foreach ($skillsMigrations as $file) {
(require $file)->up();
}
@@ -96,6 +120,152 @@ class InvestmentZoneTest extends TestCase
$this->assertDatabaseCount('investment_zones', 1);
}
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]]);
$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',
'supports' => 'Existence and project status only; no availability claim.', 'source_date' => null]];
$id = $this->actingAs($editor)->postJson('/api/v2/investment/admin/zones', [
'code' => 'QA-GENERAL-PARK', 'name' => 'Synthetic planned industrial park', 'category' => 'industrial_park',
'physical_category' => 'industrial_logistics_park', 'legal_regime' => 'pending', 'development_status' => 'planned',
'availability_status' => 'not_informed', 'description' => 'A planned informational park record.', 'province_id' => $province,
'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->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');
$this->assertStringStartsWith("\xEF\xBB\xBF", $csv->streamedContent());
$this->assertStringContainsString('Regime;Desenvolvimento;Disponibilidade', $csv->streamedContent());
$this->assertStringContainsString('Synthetic planned industrial park', $csv->streamedContent());
$this->assertStringContainsString('https://example.test/munhava', $csv->streamedContent());
$this->getJson('/api/v2/investment/zones?availability_status=confirmed')->assertJsonPath('records.total', 0);
$this->assertDatabaseHas('investment_zones', ['id' => $id, 'operator_id' => null, 'legal_source_id' => null, 'publication_status' => 'published']);
}
public function test_zone_record_separates_physical_type_and_legal_regime_and_searches_multiple_reviewed_territories_once(): void
{
$editor = $this->manager();
$legalReviewer = $this->manager();
$territoryReviewer = $this->manager();
$publisher = $this->manager();
config(['investment-zones.legal_reviewers' => [$legalReviewer->email], 'investment-zones.territory_reviewers' => [$territoryReviewer->email], 'investment-zones.publishers' => [$publisher->email]]);
$country = $this->geoNode('country', 'Synthetic Mozambique', null);
$province = $this->geoNode('province', 'Synthetic Zambézia', $country);
$districtA = $this->geoNode('district', 'Synthetic Mocuba', $province);
$districtB = $this->geoNode('district', 'Synthetic Lugela', $province);
$source = $this->actingAs($editor)->postJson('/api/v2/investment/admin/legal-sources', [
'title' => 'Synthetic zone creation act', 'url' => 'https://example.test/zone-act', 'diploma' => 'Synthetic act',
'article' => 'Article 1', 'competent_entity' => 'Synthetic authority', 'valid_from' => today()->toDateString(),
])->assertCreated()->json('id');
$this->actingAs($legalReviewer)->postJson('/api/v2/investment/admin/legal-sources/'.$source.'/validate', ['version_no' => 1])->assertOk();
$zoneId = $this->actingAs($editor)->postJson('/api/v2/investment/admin/zones', [
'code' => 'SYNTHETIC-MULTI-ZEE', 'category' => 'zee', 'physical_category' => 'economic_zone', 'legal_regime' => 'zee',
'name' => 'Synthetic Mocuba scope', 'name_en' => 'Synthetic Mocuba scope', 'description' => 'Synthetic test record.', 'description_en' => 'Synthetic test record.',
'legal_source_id' => $source, 'province_id' => $province,
'activities' => [['name' => 'Agriculture', 'status' => 'potential', 'source_reference' => 'Synthetic test source']],
'locations' => [
['geo_location_id' => $districtA, 'scope_type' => 'legal_scope', 'source_reference' => 'Synthetic legal territory source', 'legal_source_id' => $source],
['geo_location_id' => $districtB, 'scope_type' => 'legal_scope', 'source_reference' => 'Synthetic legal territory source', 'legal_source_id' => $source],
],
])->assertCreated()->json('id');
$links = DB::table('investment_zone_locations')->where('zone_id', $zoneId)->orderBy('geo_location_id')->get(['id', 'version_no']);
$this->assertCount(2, $links);
foreach ($links as $link) {
$this->actingAs($territoryReviewer)->postJson('/api/v2/investment/admin/zone-locations/'.$link->id.'/validate', ['version_no' => $link->version_no])->assertOk();
}
$this->actingAs($publisher)->postJson('/api/v2/investment/admin/zones/'.$zoneId.'/publish', ['version_no' => 1])->assertOk();
$this->getJson('/api/v2/investment/zones?province_id='.$province)->assertOk()->assertJsonPath('records.total', 1)->assertJsonPath('records.data.0.id', $zoneId);
$this->getJson('/api/v2/investment/zones?province_id='.$province.'&district_id='.$districtA)->assertOk()->assertJsonPath('records.total', 1);
$this->getJson('/api/v2/investment/zones?province_id='.$province.'&district_id='.$districtB)->assertOk()->assertJsonPath('records.total', 1);
$this->getJson('/api/v2/investment/zones?province_id='.$province.'&activity=Agriculture')->assertOk()->assertJsonPath('records.total', 1);
$this->assertDatabaseHas('investment_zones', ['id' => $zoneId, 'operator_id' => null, 'publication_status' => 'published']);
$this->assertDatabaseHas('investment_zones', ['id' => $zoneId, 'physical_category' => 'economic_zone', 'legal_regime' => 'zee']);
$this->assertDatabaseCount('investment_zone_locations', 2);
}
public function test_initial_zone_import_is_idempotent_and_keeps_records_private_until_review(): void
{
$actor = $this->manager();
$country = $this->geoNode('country', 'Synthetic Mozambique import', null);
$maputo = $this->geoNode('province', 'Synthetic Maputo', $country);
$nampula = $this->geoNode('province', 'Synthetic Nampula', $country);
$sofala = $this->geoNode('province', 'Synthetic Sofala', $country);
$zambezia = $this->geoNode('province', 'Synthetic Zambézia import', $country);
$districts = [
'BOANE' => $this->geoNode('district', 'BOANE', $maputo),
'MOSSURIL' => $this->geoNode('district', 'MOSSURIL', $nampula),
'CIDADE DA BEIRA' => $this->geoNode('district', 'CIDADE DA BEIRA', $sofala),
'MOCUBA' => $this->geoNode('district', 'MOCUBA', $zambezia),
'LUGELA' => $this->geoNode('district', 'LUGELA', $zambezia),
'NACALA-PORTO' => $this->geoNode('district', 'NACALA-PORTO', $nampula),
'NACALA-VELHA' => $this->geoNode('district', 'NACALA-VELHA', $nampula),
];
$this->geoNode('admin_post', 'MATOLA RIO', $districts['BOANE']);
$this->geoNode('admin_post', 'MATIBANE', $districts['MOSSURIL']);
$this->geoNode('admin_post', 'MUNHAMADE', $districts['LUGELA']);
$this->geoNode('admin_post', 'CIDADE DE MOCUBA', $districts['MOCUBA']);
$this->artisan('investment-zones:import-initial', ['--apply' => true, '--actor' => $actor->id])->assertSuccessful();
$this->assertDatabaseCount('investment_zones', 7);
$this->assertDatabaseCount('investment_zone_locations', 9);
$this->assertDatabaseCount('investment_legal_sources', 6);
$this->assertSame(7, DB::table('investment_zones')->where('publication_status', 'draft')->where('validation_status', 'pending')->count());
$this->assertDatabaseCount('investment_zones', 7);
$this->artisan('investment-zones:import-initial', ['--apply' => true, '--actor' => $actor->id])->assertSuccessful();
$this->assertDatabaseCount('investment_zones', 7);
$this->assertDatabaseCount('investment_zone_locations', 9);
}
public function test_industrial_candidate_import_is_exact_idempotent_keeps_ambiguity_and_revubue_single(): void
{
$actor = $this->manager();
$country = $this->geoNode('country', 'Synthetic country industrial candidates', null);
$nampulaProvince = $this->geoNode('province', 'NAMPULA', $country);
$cabo = $this->geoNode('province', 'Synthetic Cabo Delgado', $country);
$tete = $this->geoNode('province', 'Synthetic Tete', $country);
$sofala = $this->geoNode('province', 'Synthetic Sofala industrial', $country);
$this->geoNode('district', 'LARDE', $nampulaProvince);
$this->geoNode('district', 'NAMPULA', $nampulaProvince);
foreach (['MONTEPUEZ', 'BALAMA', 'ANCUABE', 'PALMA'] as $name) {
$this->geoNode('district', $name, $cabo);
}
$chiuta = $this->geoNode('district', 'CHIUTA', $tete);
$moatize = $this->geoNode('district', 'MOATIZE', $tete);
$this->geoNode('district', 'CIDADE DA BEIRA', $sofala);
$this->artisan('investment-zones:import-industrial-candidates')->assertSuccessful();
$this->assertDatabaseCount('investment_zones', 0);
$this->artisan('investment-zones:import-industrial-candidates', ['--apply' => true, '--actor' => $actor->id])->assertSuccessful();
$this->assertDatabaseCount('investment_zones', 9);
$this->assertDatabaseCount('investment_zone_locations', 10);
$this->assertDatabaseCount('investment_legal_sources', 0);
$revubue = DB::table('investment_zones')->where('code', 'MOZ-REVUBUE-ZFI')->first();
$this->assertSame('draft', $revubue->publication_status);
$this->assertSame('planned', $revubue->development_status);
$this->assertSame(2, DB::table('investment_zone_locations')->where('zone_id', $revubue->id)->whereIn('geo_location_id', [$chiuta, $moatize])->count());
$this->assertSame('reported', DB::table('investment_zones')->where('code', 'MOZ-TOPUITO-ZFI')->value('area_components->0->status'));
$this->artisan('investment-zones:import-industrial-candidates', ['--apply' => true, '--actor' => $actor->id])->assertSuccessful();
$this->assertDatabaseCount('investment_zones', 9);
$this->assertDatabaseCount('investment_zone_locations', 10);
$this->assertDatabaseCount('investment_zone_revisions', 9);
}
private function geoNode(string $type, string $name, ?string $parent): string
{
$id = (string) Str::uuid();
DB::table('geo_locations')->insert(['id' => $id, 'source_system' => 'cartografia-workbook', 'external_id' => '964a187ad32ea553b9e112cd159caa90b900050c42b7329594a75bcd798a96ff:'.$id,
'version_no' => 1, 'data_classification' => 'public', 'name' => $name, 'location_type' => $type, 'parent_id' => $parent,
'code' => $id, 'source_code' => null, 'created_at' => now(), 'updated_at' => now()]);
return $id;
}
public function test_validated_relations_filter_the_same_opportunity_and_revoked_sources_disappear(): void
{
$editor = $this->manager();
@@ -111,11 +281,14 @@ class InvestmentZoneTest extends TestCase
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);
$zoneIds = [];
foreach (['zee', 'zfi'] as $category) {
$this->actingAs($editor);
$zoneId = $this->postJson('/api/v2/investment/admin/zones', ['code' => 'QA-'.$category, 'name' => 'Synthetic '.$category,
'category' => $category, 'name_en' => 'Synthetic zone', 'description' => 'Synthetic description', 'description_en' => 'Synthetic description',
'category' => $category, 'physical_category' => $category === 'zfi' ? 'industrial_free_zone' : 'economic_zone', 'legal_regime' => $category,
'province_id' => $zoneProvince, 'name_en' => 'Synthetic zone', 'description' => 'Synthetic description', 'description_en' => 'Synthetic description',
'operator_id' => $organization, 'legal_source_id' => $source])->assertCreated()->json('id');
$linkPayload = ['opportunity_id' => $opportunity->id, 'association_type' => 'potential', 'role' => 'potential',
'source_reference' => 'Synthetic relationship evidence', 'justification' => 'Synthetic potential investment', 'valid_from' => today()->toDateString()];