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

70 lines
4.6 KiB
PHP

<?php
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
require dirname(__DIR__).'/vendor/autoload.php';
require __DIR__.'/portal-qa-environment.php';
$target = portalQaEnvironment();
$app = require dirname(__DIR__).'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
portalQaAssertTarget($target);
abort_if(config('portal.notifications_enabled'), 409, 'QA visual intake requires outgoing notifications disabled.');
DB::beginTransaction();
DB::statement('SET TRANSACTION READ ONLY');
$proof = ['captured_at' => gmdate('c'), 'target' => $target, 'read_only' => true, 'active_writes' => 0, 'outgoing_notifications_enabled' => false];
if (in_array('--preflight', $argv, true)) {
$proof['intl_extension'] = extension_loaded('intl');
$proof['idn_conversion_available'] = function_exists('idn_to_ascii');
$proof['dns_email_validation'] = [];
foreach (['example.com', 'example.org', 'gmail.com'] as $domain) {
$proof['dns_email_validation'][$domain] = Validator::make(['email' => 'qa-synthetic-country-test@'.$domain], ['email' => 'email:rfc,dns'])->passes();
}
DB::rollBack();
file_put_contents(storage_path('app/private/investmoz-v2/portal-audit/country-paths-preflight-qa.json'), json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode($proof).PHP_EOL;
exit;
}
$file = storage_path('app/private/investmoz-v2/portal-audit/country-paths-chromium-20261010.json');
if (in_array('--entry-source', $argv, true)) {
$browser = json_decode(file_get_contents(storage_path('app/private/investmoz-v2/portal-audit/form-entry-source-chromium-20261010.json')), true, 512, JSON_THROW_ON_ERROR);
abort_unless($browser['result'] === 'passed', 409);
$rows = DB::table('interest_requests')->where('email', $browser['entry']['email'])->whereNull('deleted_at')->get();
abort_unless(count($rows) === 1, 422);
$row = $rows[0];
$metadata = json_decode($row->metadata, true, 512, JSON_THROW_ON_ERROR);
abort_unless($row->source_page === '/formularios/investidor' && $row->country === 'PT' && $metadata['declared_origin_country_code'] === 'ZA', 422);
$proof['entry'] = ['id' => $row->id, 'reference' => $row->reference, 'source_page' => $row->source_page,
'country' => $row->country, 'origin' => $metadata['declared_origin_country_code'], 'exactly_one_record' => true];
DB::rollBack();
$proof['result'] = 'passed_read_only_entry_source';
file_put_contents(storage_path('app/private/investmoz-v2/portal-audit/form-entry-source-persistence-qa.json'), json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode(['result' => $proof['result'], 'target' => $target, 'active_writes' => 0]).PHP_EOL;
exit;
}
$browser = json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR);
abort_unless($browser['result'] === 'passed', 409);
$proof['forms'] = [];
foreach ($browser['forms'] as $route => $entry) {
$rows = DB::table('interest_requests')->where('email', $entry['email'])->whereNull('deleted_at')->get();
abort_unless(count($rows) === 1, 422);
$row = $rows[0];
$metadata = json_decode($row->metadata, true, 512, JSON_THROW_ON_ERROR);
abort_unless($row->reference === $entry['reference'] && $row->country === 'PT' && $metadata['declared_origin_country_code'] === 'ZA', 422);
$consents = DB::table('consents')->where('interest_request_id', $row->id)->where('purpose', 'respond_to_interest')->count();
$receiptCount = DB::table('interest_submission_receipts')->where('interest_request_id', $row->id)->count();
abort_unless($consents === 1 && $receiptCount === 1, 422);
$proof['forms'][$route] = ['id' => $row->id, 'reference' => $row->reference, 'country' => $row->country,
'declared_origin' => $metadata['declared_origin_country_code'], 'status' => $row->status,
'exactly_one_record' => true, 'consents' => $consents, 'idempotency_receipts' => $receiptCount,
'source_page' => $row->source_page, 'kind' => $metadata['kind'] ?? 'manifestation'];
}
abort_unless(DB::table('interest_requests')->where('email', 'qa-ab-countries-3-20261010@example.invalid')->count() === 0, 422);
$proof['dns_invalid_attempt_wrote_no_request'] = true;
DB::rollBack();
$proof['result'] = 'passed_read_only_four_form_intakes';
$output = storage_path('app/private/investmoz-v2/portal-audit/country-paths-persistence-qa.json');
file_put_contents($output, json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode(['result' => $proof['result'], 'target' => $target, 'forms' => count($proof['forms']), 'active_writes' => 0]).PHP_EOL;