175 lines
7.0 KiB
PHP
175 lines
7.0 KiB
PHP
<?php
|
|
/**
|
|
* One-off smoke test: Claims Collection V2 dashboard.
|
|
* Run: php tests/smoke_claims_collection_v2.php [policy_id]
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
ob_start();
|
|
|
|
define('FCPATH', __DIR__ . '/../public/');
|
|
chdir(FCPATH);
|
|
|
|
require FCPATH . '../app/Config/Paths.php';
|
|
$paths = new Config\Paths();
|
|
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';
|
|
require_once SYSTEMPATH . 'Config/DotEnv.php';
|
|
(new CodeIgniter\Config\DotEnv(ROOTPATH))->load();
|
|
|
|
defined('ENVIRONMENT') || define('ENVIRONMENT', env('CI_ENVIRONMENT', 'development'));
|
|
|
|
$boot = APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php';
|
|
if (is_file($boot)) {
|
|
require_once $boot;
|
|
}
|
|
|
|
// Load autoloaded services without full HTTP stack.
|
|
helper('url');
|
|
|
|
use App\Controllers\ClaimsCollectionV2DashboardController;
|
|
use App\Models\ClaimsCollectionV2DashboardModel;
|
|
use Config\Services;
|
|
|
|
$policyId = isset($argv[1]) ? (int) $argv[1] : 4687;
|
|
$pass = 0;
|
|
$fail = 0;
|
|
$results = [];
|
|
|
|
function ok(string $label, bool $cond, string $detail = ''): void
|
|
{
|
|
global $pass, $fail, $results;
|
|
if ($cond) {
|
|
$pass++;
|
|
$results[] = '[PASS] ' . $label . ($detail ? " — {$detail}" : '');
|
|
} else {
|
|
$fail++;
|
|
$results[] = '[FAIL] ' . $label . ($detail ? " — {$detail}" : '');
|
|
}
|
|
}
|
|
|
|
$model = new ClaimsCollectionV2DashboardModel();
|
|
$kpiMap = ClaimsCollectionV2DashboardModel::KPI_MAP;
|
|
|
|
ok('KPI_MAP count', count($kpiMap) === 36, (string) count($kpiMap));
|
|
|
|
$uniqueMethods = array_unique(array_values($kpiMap));
|
|
ok('unique KPI method names', count($uniqueMethods) === 36, count($uniqueMethods) . ' methods');
|
|
|
|
foreach (['policy_exposure_summary', 'incurred_ratio'] as $slug) {
|
|
ok("slug map contains {$slug}", in_array($slug, $kpiMap, true));
|
|
}
|
|
ok('id 207 maps to incurred_ratio', ($kpiMap[207] ?? '') === 'incurred_ratio');
|
|
ok('id 181 maps to policy_exposure_summary', ($kpiMap[181] ?? '') === 'policy_exposure_summary');
|
|
|
|
try {
|
|
$rows = $model->policy_exposure_summary($policyId);
|
|
ok('model policy_exposure_summary', is_array($rows), 'rows=' . count($rows));
|
|
} catch (Throwable $e) {
|
|
ok('model policy_exposure_summary', false, $e->getMessage());
|
|
}
|
|
|
|
try {
|
|
$rows = $model->getKpi('incurred_ratio', $policyId);
|
|
ok('model getKpi(incurred_ratio)', is_array($rows), 'rows=' . count($rows));
|
|
} catch (Throwable $e) {
|
|
ok('model getKpi(incurred_ratio)', false, $e->getMessage());
|
|
}
|
|
|
|
try {
|
|
$rows = $model->getKpi('premium_as_on_date', $policyId);
|
|
$val = is_array($rows) && isset($rows[0]['premium_as_on_date']) ? (string) $rows[0]['premium_as_on_date'] : '';
|
|
ok('model premium_as_on_date (#185)', count($rows) === 1 && str_starts_with($val, '💰'), $val ?: 'empty');
|
|
} catch (Throwable $e) {
|
|
ok('model premium_as_on_date (#185)', false, $e->getMessage());
|
|
}
|
|
|
|
try {
|
|
$rows = $model->premium_as_on_date_legacy($policyId);
|
|
ok('model premium_as_on_date_legacy callable', is_array($rows), 'rows=' . count($rows));
|
|
} catch (Throwable $e) {
|
|
ok('model premium_as_on_date_legacy callable', false, $e->getMessage());
|
|
}
|
|
|
|
$request = Services::request(null, false);
|
|
$response = Services::response();
|
|
$request->setGlobal('get', ['client_policy' => (string) $policyId]);
|
|
|
|
$controller = new ClaimsCollectionV2DashboardController();
|
|
$controller->initController($request, $response, service('logger'));
|
|
|
|
$slugResp = json_decode($controller->kpi('incurred_ratio')->getJSON(), true);
|
|
ok('controller kpi by slug', ($slugResp['status'] ?? false) === true && ($slugResp['kpi'] ?? '') === 'incurred_ratio');
|
|
|
|
$idResp = json_decode($controller->kpi('207')->getJSON(), true);
|
|
ok('controller kpi by id 207', ($idResp['status'] ?? false) === true && ($idResp['kpi_id'] ?? 0) === 207);
|
|
|
|
$premResp = json_decode($controller->kpi('185')->getJSON(), true);
|
|
ok('controller kpi by id 185', ($premResp['status'] ?? false) === true && ($premResp['kpi'] ?? '') === 'premium_as_on_date' && ! empty($premResp['rows'][0]['premium_as_on_date'] ?? ''));
|
|
|
|
$badResp = json_decode($controller->kpi('not_a_kpi')->getJSON(), true);
|
|
ok('controller unknown kpi 404', ($badResp['status'] ?? true) === false);
|
|
|
|
$allResp = json_decode($controller->all()->getJSON(), true);
|
|
ok('controller all KPIs', ($allResp['status'] ?? false) === true && count($allResp['data'] ?? []) === 36);
|
|
|
|
$debugOut = $controller->debug($policyId);
|
|
$debugBody = is_string($debugOut) ? $debugOut : $debugOut->getBody();
|
|
$debugJson = json_decode($debugBody, true);
|
|
ok('controller debug JSON', ($debugJson['status'] ?? false) === true && isset($debugJson['data']));
|
|
|
|
$previewOut = $controller->preview($policyId);
|
|
$previewHtml = is_string($previewOut) ? $previewOut : $previewOut->getBody();
|
|
ok('controller preview HTML', str_contains($previewHtml, 'Claims Collection V2') && str_contains($previewHtml, 'kpi-grid'));
|
|
|
|
$routeCollection = Services::routes(true);
|
|
$mvcRoutes = [];
|
|
$jwtRoutes = [];
|
|
foreach ($routeCollection->getRoutes('get') as $pattern => $handler) {
|
|
if (! str_contains($pattern, 'claims-collection-v2')) {
|
|
continue;
|
|
}
|
|
if (str_starts_with($pattern, 'util/')) {
|
|
$mvcRoutes[] = $pattern;
|
|
}
|
|
if (str_starts_with($pattern, 'employeeRest/')) {
|
|
$jwtRoutes[] = $pattern;
|
|
}
|
|
}
|
|
|
|
ok('MVC claims-collection-v2 routes registered', count($mvcRoutes) >= 5, implode(', ', $mvcRoutes) ?: 'none');
|
|
ok('JWT claims-collection-v2 routes registered', count($jwtRoutes) >= 5, implode(', ', $jwtRoutes) ?: 'none');
|
|
|
|
$baseUrl = rtrim((string) env('app.baseURL', ''), '/');
|
|
if ($baseUrl !== '') {
|
|
$results[] = '';
|
|
$results[] = '=== HTTP auth gate checks (no session/token) ===';
|
|
$urls = [
|
|
'MVC preview' => $baseUrl . '/util/claims-collection-v2/preview?client_policy=' . $policyId,
|
|
'MVC kpi slug' => $baseUrl . '/util/claims-collection-v2/kpi/incurred_ratio?client_policy=' . $policyId,
|
|
'MVC kpi id' => $baseUrl . '/util/claims-collection-v2/kpi/207?client_policy=' . $policyId,
|
|
'MVC debug' => $baseUrl . '/util/claims-collection-v2/debug?client_policy=' . $policyId,
|
|
'JWT kpi slug' => $baseUrl . '/employeeRest/claims-collection-v2/kpi/incurred_ratio?client_policy=' . $policyId,
|
|
'JWT debug' => $baseUrl . '/employeeRest/claims-collection-v2/debug?client_policy=' . $policyId,
|
|
];
|
|
foreach ($urls as $label => $url) {
|
|
$ctx = stream_context_create(['http' => ['ignore_errors' => true, 'timeout' => 10]]);
|
|
$body = @file_get_contents($url, false, $ctx);
|
|
$code = 0;
|
|
if (isset($http_response_header[0]) && preg_match('/\s(\d{3})\s/', $http_response_header[0], $m)) {
|
|
$code = (int) $m[1];
|
|
}
|
|
$blocked = in_array($code, [401, 403, 302, 303], true);
|
|
$reachable = $code >= 200 && $code < 500;
|
|
ok("HTTP {$label} (" . ($code ?: 'no connection') . ')', $blocked || $reachable, $url);
|
|
}
|
|
} else {
|
|
$results[] = '[SKIP] HTTP checks — app.baseURL not set in .env';
|
|
}
|
|
|
|
ob_end_clean();
|
|
echo '=== Claims Collection V2 smoke test (policy_id=' . $policyId . ') ===' . PHP_EOL . PHP_EOL;
|
|
echo implode(PHP_EOL, $results) . PHP_EOL;
|
|
echo PHP_EOL . "=== Summary: {$pass} passed, {$fail} failed ===" . PHP_EOL;
|
|
exit($fail > 0 ? 1 : 0);
|