Files
Investidor-V2/tools/opportunity-workflow-fixtures-qa.php
T
nala 01405cbf8a
tests / ci (push) Canceled after 0s
oportunidades 5
2026-10-10 14:15:28 +02:00

51 lines
3.6 KiB
PHP

<?php
// Explicitly synthetic reference data for QA; never official or suitable for active import.
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
$root = dirname(__DIR__);
require $root.'/vendor/autoload.php';
require __DIR__.'/portal-qa-environment.php';
$target = portalQaEnvironment();
$app = require $root.'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$identity = portalQaAssertTarget($target);
$directory = $root.'/storage/app/private/investmoz-v2/portal-audit';
$path = $directory.'/opportunity-workflow-fixtures-qa.json';
if (is_file($path)) {
$receipt = json_decode(file_get_contents($path), true, 512, JSON_THROW_ON_ERROR);
throw_unless($receipt['target']['database'] === $identity->database && DB::table('economic_activities')->where('id', $receipt['activity_id'])->exists(), RuntimeException::class, 'Existing fixture target/reference mismatch');
echo json_encode(['target' => $identity, 'synthetic_fixture_reused' => true, 'active_writes' => 0]).PHP_EOL;
exit;
}
$orgs = json_decode(file_get_contents($directory.'/profiles-v1-organizations-qa.json'), true, 512, JSON_THROW_ON_ERROR);
$receipt = DB::transaction(function () use ($identity, $orgs) {
$version = (string) Str::uuid();
DB::table('reference_catalog_versions')->insert(['id' => $version, 'catalog_code' => 'qa-opportunity-synthetic', 'version_no' => 1,
'source_system' => 'qa-synthetic-fixture', 'source_version' => 'qa-20261010', 'source_reference' => 'Synthetic test data only, not an official economic classification',
'status' => 'published', 'created_at' => now(), 'updated_at' => now()]);
$previous = null;
$ids = [];
foreach (['Sector sintético QA', 'Subsector sintético QA', 'Atividade sintética QA'] as $i => $name) {
$sector = DB::table('sectors')->insertGetId(['name' => $name, 'slug' => 'qa-workflow-level-'.$i, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()]);
$id = (string) Str::uuid();
DB::table('economic_activities')->insert(['id' => $id, 'catalog_version_id' => $version, 'parent_id' => $previous,
'sector_id' => $sector, 'code' => 'qa-level-'.$i, 'label_pt_mz' => $name, 'status' => 'published', 'valid_from' => '2026-10-10', 'created_at' => now(), 'updated_at' => now()]);
$ids[] = ['id' => $id, 'sector_id' => $sector];
$previous = $id;
}
$investor = (string) Str::uuid();
$contact = (string) Str::uuid();
DB::table('investors')->insert(['id' => $investor, 'source_system' => 'qa-synthetic-fixture', 'organization_id' => $orgs['organization'],
'legal_name' => 'Entidade sintética QA — sem validade real', 'investor_type' => 'institutional', 'status' => 'active']);
DB::table('contacts')->insert(['id' => $contact, 'source_system' => 'qa-synthetic-fixture', 'full_name' => 'Contacto sintético QA — oportunidade', 'email' => 'workflow-contact@example.invalid']);
DB::table('investor_contacts')->insert(['investor_id' => $investor, 'contact_id' => $contact, 'is_primary' => true]);
return ['target' => $identity, 'synthetic_only' => true, 'sector_id' => $ids[0]['sector_id'], 'subsector_id' => $ids[1]['id'], 'activity_id' => $ids[2]['id'],
'contact_id' => $contact, 'organization_id' => $orgs['organization'], 'catalog_version_id' => $version, 'active_writes' => 0];
});
file_put_contents($path, json_encode($receipt, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode(['target' => $identity, 'synthetic_only' => true, 'canonical_reference_fixture_prepared' => true, 'active_writes' => 0]).PHP_EOL;