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
+57 -4
View File
@@ -2,12 +2,14 @@
namespace Tests\Feature;
use App\Models\DevelopmentCorridor;
use App\Models\EconomicCluster;
use App\Models\Project;
use App\Models\User;
use App\Models\ValueChain;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Inertia\Testing\AssertableInertia;
use Tests\TestCase;
class InvestmentStructureTest extends TestCase
@@ -47,11 +49,16 @@ class InvestmentStructureTest extends TestCase
$cluster = EconomicCluster::firstOrFail();
$project = Project::factory()->create();
$url = '/management/clusters/'.$cluster->id.'/projects';
$this->post($url, ['project_id' => $project->id, 'role' => 'anchor'])->assertSessionHasNoErrors();
$this->post($url, ['project_id' => $project->id, 'role' => 'anchor'])->assertSessionHasNoErrors();
$association = ['project_id' => $project->id, 'version_no' => 0, 'role' => 'anchor', 'association_type' => 'potential',
'source_reference' => 'Referencia de planeamento sintético', 'evidence_reference' => 'fixture:test:cluster-link',
'valid_from' => today()->toDateString()];
$this->post($url, $association)->assertSessionHasNoErrors();
$this->post($url, $association)->assertStatus(409);
$this->assertDatabaseCount('cluster_projects', 1);
$this->post($url, ['project_id' => $project->id, 'role' => 'supporting'])->assertSessionHasNoErrors();
$this->assertDatabaseHas('cluster_projects', ['project_id' => $project->id, 'role' => 'supporting']);
$this->post($url, [...$association, 'version_no' => 1])->assertSessionHasNoErrors();
$this->assertDatabaseHas('cluster_projects', ['project_id' => $project->id, 'version_no' => 1]);
$this->post($url, [...$association, 'version_no' => 1, 'role' => 'supporting'])->assertSessionHasNoErrors();
$this->assertDatabaseHas('cluster_projects', ['project_id' => $project->id, 'role' => 'supporting', 'version_no' => 2, 'validation_status' => 'pending']);
$this->assertSame(2, DB::table('audit_events')->where('entity_type', 'cluster_projects')->count());
$project->delete();
$this->post($url, ['project_id' => $project->id, 'role' => 'anchor'])->assertSessionHasErrors('project_id');
@@ -80,6 +87,52 @@ class InvestmentStructureTest extends TestCase
$this->actingAs(User::factory()->create());
$this->get('/management/projects')->assertForbidden();
$this->post('/management/clusters', [])->assertForbidden();
$this->get('/management/corridors')->assertForbidden();
$this->post('/management/corridors', [])->assertForbidden();
$this->assertDatabaseCount('economic_clusters', 0);
$this->assertDatabaseCount('development_corridors', 0);
}
public function test_development_corridors_have_private_crud_with_supported_fields_and_statuses(): void
{
$this->manager();
$data = ['code' => 'COR-TEST', 'name' => 'Corredor de teste', 'status' => 'proposed',
'description' => 'Descrição sintética para validar o cadastro administrativo.'];
$this->post('/management/corridors', $data)->assertSessionHasNoErrors()->assertRedirect();
$corridor = DevelopmentCorridor::firstOrFail();
$this->assertSame('internal', $corridor->data_classification);
$this->assertDatabaseHas('development_corridors', ['id' => $corridor->id, 'status' => 'proposed']);
$this->get('/management/corridors')->assertInertia(fn (AssertableInertia $page) => $page
->component('structures/index')->where('structure', 'corridors')->has('records.data', 1));
$this->get('/management/corridors/'.$corridor->id.'/edit')->assertInertia(fn (AssertableInertia $page) => $page
->component('structures/editor')->where('structure', 'corridors')->where('record.id', $corridor->id));
$this->put('/management/corridors/'.$corridor->id, [...$data, 'status' => 'active', 'description' => 'Descrição actualizada.'])
->assertSessionHasNoErrors();
$this->assertDatabaseHas('development_corridors', ['id' => $corridor->id, 'status' => 'active', 'description' => 'Descrição actualizada.']);
}
public function test_structure_relations_require_sources_and_independent_review(): void
{
$editor = User::factory()->create();
$reviewer = User::factory()->create();
config(['portal.managers' => [$editor->email, $reviewer->email]]);
$cluster = EconomicCluster::create(['code' => 'REL-C1', 'name' => 'Cluster relacional', 'sector' => 'Energia', 'status' => 'planned']);
$project = Project::factory()->create();
$url = '/management/structure-relations/cluster-project';
$payload = ['cluster_id' => $cluster->id, 'project_id' => $project->id, 'role' => 'anchor',
'association_type' => 'official', 'source_reference' => 'Diploma oficial, artigo 4, secao 2',
'evidence_reference' => 'fixture:test:evidence-01', 'valid_from' => today()->toDateString()];
$this->actingAs($editor)->post($url, [...$payload, 'source_reference' => 'curta'])->assertSessionHasErrors('source_reference');
$this->post($url, $payload)->assertSessionHasNoErrors();
$relation = DB::table('cluster_projects')->where('cluster_id', $cluster->id)->where('project_id', $project->id)->first();
$this->assertSame('pending', $relation->validation_status);
$this->assertSame($editor->id, $relation->editor_id);
$this->post('/management/structure-relations/cluster-project/'.$relation->id.'/validate', ['version_no' => 1])->assertForbidden();
$this->actingAs($reviewer)->post('/management/structure-relations/cluster-project/'.$relation->id.'/validate', ['version_no' => 1])->assertSessionHasNoErrors();
$this->assertDatabaseHas('cluster_projects', ['id' => $relation->id, 'validation_status' => 'validated', 'validator_id' => $reviewer->id, 'version_no' => 2]);
$this->post('/management/structure-relations/cluster-project/'.$relation->id.'/revoke', ['version_no' => 1])->assertStatus(409);
}
}