186 lines
6.6 KiB
PHP
186 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* Smoke test: EmployeeRestController::getInsurerClaimFormDownloadUrl
|
|
* Run: php tests/smoke_get_insurer_claim_form_download_url.php [client_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;
|
|
}
|
|
|
|
use App\Controllers\EmployeeRestController;
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
use CodeIgniter\HTTP\URI;
|
|
use Config\Services;
|
|
|
|
$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}" : '');
|
|
}
|
|
}
|
|
|
|
function invokeApi(EmployeeRestController $controller, array $query): array
|
|
{
|
|
$uri = new URI('http://localhost/nhance_v2/employeeRest/getInsurerClaimFormDownloadUrl');
|
|
if ($query !== []) {
|
|
$uri->setQuery(http_build_query($query));
|
|
}
|
|
|
|
$request = new IncomingRequest(
|
|
config('App'),
|
|
$uri,
|
|
null,
|
|
new \CodeIgniter\HTTP\UserAgent()
|
|
);
|
|
$request->setGlobal('get', $query);
|
|
|
|
$response = Services::response();
|
|
$logger = Services::logger();
|
|
$controller->initController($request, $response, $logger);
|
|
|
|
$response = $controller->getInsurerClaimFormDownloadUrl();
|
|
$body = json_decode($response->getBody(), true);
|
|
|
|
return is_array($body) ? $body : [];
|
|
}
|
|
|
|
$db = db_connect('default');
|
|
$controller = new EmployeeRestController();
|
|
|
|
$legacyPolicy = $db->query(
|
|
"SELECT cp.id AS client_policy_id, i.short_name
|
|
FROM client_policy cp
|
|
JOIN insurers i ON i.id = cp.insurer_id
|
|
WHERE cp.is_active = 1
|
|
AND i.is_active = 1
|
|
AND i.short_name = 'ICICIPRU'
|
|
LIMIT 1"
|
|
)->getRowArray();
|
|
|
|
$uploadedPolicy = $db->query(
|
|
"SELECT cp.id AS client_policy_id, i.short_name, i.insurer_claim_form
|
|
FROM client_policy cp
|
|
JOIN insurers i ON i.id = cp.insurer_id
|
|
WHERE cp.is_active = 1
|
|
AND i.is_active = 1
|
|
AND i.insurer_claim_form IS NOT NULL
|
|
AND i.insurer_claim_form <> ''
|
|
LIMIT 1"
|
|
)->getRowArray();
|
|
|
|
$inactivePolicy = $db->query(
|
|
'SELECT id AS client_policy_id FROM client_policy WHERE is_active = 0 LIMIT 1'
|
|
)->getRowArray();
|
|
|
|
$missingParam = invokeApi($controller, []);
|
|
ok('Missing client_policy_id returns 400', ($missingParam['code'] ?? null) === 400, json_encode($missingParam));
|
|
|
|
$invalidParam = invokeApi($controller, ['client_policy_id' => 'abc']);
|
|
ok('Invalid client_policy_id returns 400', ($invalidParam['code'] ?? null) === 400, json_encode($invalidParam));
|
|
|
|
$notFound = invokeApi($controller, ['client_policy_id' => '999999999']);
|
|
ok('Unknown client_policy_id returns 404', ($notFound['code'] ?? null) === 404, json_encode($notFound));
|
|
|
|
if (!empty($inactivePolicy['client_policy_id'])) {
|
|
$inactive = invokeApi($controller, ['client_policy_id' => (string) $inactivePolicy['client_policy_id']]);
|
|
ok('Inactive client policy returns 404', ($inactive['code'] ?? null) === 404, json_encode($inactive));
|
|
}
|
|
|
|
if (!empty($legacyPolicy['client_policy_id'])) {
|
|
$legacyPath = ROOTPATH . 'public/claim_sample_forms/' . $legacyPolicy['short_name'] . '.pdf';
|
|
$legacy = invokeApi($controller, ['client_policy_id' => (string) $legacyPolicy['client_policy_id']]);
|
|
$legacyResolved = resolve_insurer_claim_form_file(['short_name' => $legacyPolicy['short_name']]);
|
|
ok(
|
|
'No uploaded form falls back to IRDAI default (ICICIPRU policy)',
|
|
($legacy['status'] ?? false) === true
|
|
&& ($legacy['code'] ?? null) === 200
|
|
&& !empty($legacy['data']['download_url'])
|
|
&& count($legacy['data']) === 1
|
|
&& ($legacyResolved['source'] ?? '') === 'irdai_default',
|
|
'legacy_file_exists=' . (is_file($legacyPath) ? 'yes' : 'no') . ' | ' . json_encode($legacy)
|
|
);
|
|
}
|
|
|
|
$irdaiDefaultPolicy = $db->query(
|
|
"SELECT cp.id AS client_policy_id, i.short_name
|
|
FROM client_policy cp
|
|
JOIN insurers i ON i.id = cp.insurer_id
|
|
WHERE cp.is_active = 1
|
|
AND i.is_active = 1
|
|
AND (i.insurer_claim_form IS NULL OR i.insurer_claim_form = '')
|
|
AND i.short_name NOT IN ('ICICIPRU', 'DIGITLIF', 'MAXLIFE', 'NIA', 'OIC', 'PIFL', 'RELIANCE')
|
|
LIMIT 1"
|
|
)->getRowArray();
|
|
|
|
if (!empty($irdaiDefaultPolicy['client_policy_id'])) {
|
|
$irdai = invokeApi($controller, ['client_policy_id' => (string) $irdaiDefaultPolicy['client_policy_id']]);
|
|
$irdaiResolved = resolve_insurer_claim_form_file(['short_name' => $irdaiDefaultPolicy['short_name']]);
|
|
ok(
|
|
'IRDAI default claim form fallback',
|
|
($irdai['status'] ?? false) === true
|
|
&& ($irdai['code'] ?? null) === 200
|
|
&& !empty($irdai['data']['download_url'])
|
|
&& count($irdai['data']) === 1
|
|
&& ($irdaiResolved['source'] ?? '') === 'irdai_default',
|
|
json_encode($irdai)
|
|
);
|
|
}
|
|
|
|
if (!empty($uploadedPolicy['client_policy_id'])) {
|
|
$uploadedPath = WRITEPATH . 'insurer_claim_form/' . basename((string) $uploadedPolicy['insurer_claim_form']);
|
|
$uploaded = invokeApi($controller, ['client_policy_id' => (string) $uploadedPolicy['client_policy_id']]);
|
|
$uploadedResolved = resolve_insurer_claim_form_file([
|
|
'insurer_claim_form' => $uploadedPolicy['insurer_claim_form'],
|
|
'short_name' => $uploadedPolicy['short_name'] ?? '',
|
|
]);
|
|
ok(
|
|
'Uploaded claim form success',
|
|
($uploaded['status'] ?? false) === true
|
|
&& ($uploaded['code'] ?? null) === 200
|
|
&& !empty($uploaded['data']['download_url'])
|
|
&& count($uploaded['data']) === 1
|
|
&& ($uploadedResolved['source'] ?? '') === 'uploaded',
|
|
'file_exists=' . (is_file($uploadedPath) ? 'yes' : 'no') . ' | ' . json_encode($uploaded)
|
|
);
|
|
}
|
|
|
|
$cliPolicyId = $argv[1] ?? ($legacyPolicy['client_policy_id'] ?? null);
|
|
if ($cliPolicyId) {
|
|
$manual = invokeApi($controller, ['client_policy_id' => (string) $cliPolicyId]);
|
|
echo "\nManual test client_policy_id={$cliPolicyId}\n";
|
|
echo json_encode($manual, JSON_PRETTY_PRINT) . "\n";
|
|
}
|
|
|
|
echo "\nSmoke test summary: {$pass} passed, {$fail} failed\n";
|
|
foreach ($results as $line) {
|
|
echo $line . "\n";
|
|
}
|
|
|
|
exit($fail > 0 ? 1 : 0);
|