Files
Investidor-V2/tools/portal-functional-lease-inspect-qa.php
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

34 lines
2.3 KiB
PHP

<?php
// Read existing lease permissions/cases before any additional synthetic QA writes.
use App\Models\Opportunity;
use App\Models\User;
use App\Services\OpportunityManagement;
use App\Services\PortalProfileAccess;
use Illuminate\Support\Facades\DB;
$workspace = dirname(__DIR__);
$private = $workspace.'/storage/app/private/investmoz-v2/portal-audit';
$plan = json_decode(file_get_contents($private.'/portal-stability-latest.json'), true, 512, JSON_THROW_ON_ERROR);
putenv('STABILITY_QA_MODE=consumers');
$app = (static fn (string $file) => require $file)($plan['source'].'/tools/portal-stability-runtime.php');
$target = DB::selectOne('select current_database() as database,inet_server_port() as port');
throw_unless($target->database === 'stability_consumers_20261011_084534_test' && (int) $target->port === 55441, RuntimeException::class, 'Exact isolated QA required.');
$proof = DB::transaction(function () use ($target): array {
DB::statement('SET TRANSACTION READ ONLY');
$service = app(PortalProfileAccess::class);
$record = Opportunity::findOrFail(31);
$old = json_decode(file_get_contents(dirname(__DIR__).'/storage/app/private/investmoz-v2/portal-audit/functional-final-persistence-qa-20261011.json'), true, 512, JSON_THROW_ON_ERROR);
$sale = array_values(array_filter($old['categories'], fn ($row) => $row['id'] === 31))[0];
throw_unless((int) $record->management_version === $sale['version'] && ($record->workflow_context['publication']['hash'] ?? null) === $sale['publication_hash'], RuntimeException::class, 'Previously demonstrated sale case changed.');
$contexts = [];
foreach ([21, 22] as $id) {
$contexts[$id] = $service->navigation(User::findOrFail($id))['contexts'];
}
return ['result' => 'passed', 'at' => gmdate('c'), 'target' => $target, 'creation_contexts' => $contexts,
'existing_real_estate_drafts' => DB::table('opportunities')->where('opportunity_category', 'real_estate')->where('owner_user_id', 21)->whereRaw("COALESCE(workflow_context->>'working_state',status)='draft'")->get(['id', 'organization_id'])->all(),
'sale_31_unchanged' => true, 'active_writes' => 0];
});
file_put_contents($private.'/functional-lease-permissions-qa-20261011.json', json_encode($proof, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
echo json_encode($proof, JSON_THROW_ON_ERROR).PHP_EOL;