forked from Yara724/api
fix(flow-ui): enable explicit person role registration
Expose person registration for hull claims, require selection of the supported role 166 and check that role even when a driver ID is cached. Keep claim notifier validation out of person registration and populate the verified hull driver reference after success.
This commit is contained in:
@@ -831,15 +831,23 @@
|
|||||||
<select id="DRIVER_IS_OWNER"><option value="1" selected>1</option><option value="0">0</option></select>
|
<select id="DRIVER_IS_OWNER"><option value="1" selected>1</option><option value="0">0</option></select>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint">اگر این شخص در فناوران نیست، موبایل و بقیه مشخصات ثبت را در تب «ثبت شخص» وارد کنید. همان مقادیر در GEN.44 فرستاده میشود.</p>
|
<p class="hint">اگر این شخص در فناوران نیست یا برای بدنه نقش «سایر» ندارد، مشخصات او را در تب «ثبت شخص» وارد کنید.</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-panel" data-form-panel="person" hidden>
|
<div class="tab-panel" data-form-panel="person" hidden>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<h2><span class="n">+</span> ثبت شخص — GEN.44</h2>
|
<h2><span class="n">+</span> ثبت شخص — GEN.44</h2>
|
||||||
<p class="hint">وقتی استعلام نقش ۱۶۱ یا ۱۶۶ خالی است، این فیلدها در POST سایر اشخاص میروند. خالی یا کلمه null یعنی JSON null. موبایل برای این تنانت اجباری است.</p>
|
<p class="hint">برای بدنه، شخص باید نقش «سایر» (۱۶۶) داشته باشد؛ نقش بیمهگذار (۱۶۱) بهتنهایی کافی نیست. مشخصات همین فرم برای ثبت شخص استفاده میشود. خالی یا کلمه null یعنی JSON null. موبایل برای این تنانت اجباری است.</p>
|
||||||
<div class="grid 3">
|
<div class="grid 3">
|
||||||
|
<label class="s3"><b>نقش مورد نظر برای ثبت</b>
|
||||||
|
<select id="PERSON_ROLE_ID" required>
|
||||||
|
<option value="">— نقش را انتخاب کنید —</option>
|
||||||
|
<option value="166">سایر — 166 (برای ثبت راننده)</option>
|
||||||
|
<option value="161" disabled>بیمهگذار — 161 (در این سرویس قابل ثبت نیست)</option>
|
||||||
|
</select>
|
||||||
|
<span class="hint">این فرم نقش «سایر» را با سرویس ثبت سایر اشخاص اضافه میکند. نقشهای قبلی شخص حفظ میشوند.</span>
|
||||||
|
</label>
|
||||||
<label><b>کد ملی</b><input id="personNc" value="0017819199" maxlength="10" /></label>
|
<label><b>کد ملی</b><input id="personNc" value="0017819199" maxlength="10" /></label>
|
||||||
<label><b>تاریخ تولد</b><input id="personBd" value="13731228" placeholder="YYYYMMDD" /></label>
|
<label><b>تاریخ تولد</b><input id="personBd" value="13731228" placeholder="YYYYMMDD" /></label>
|
||||||
<label><b>موبایل</b><input id="DRIVER_MOBILE" placeholder="0912…" dir="ltr" /></label>
|
<label><b>موبایل</b><input id="DRIVER_MOBILE" placeholder="0912…" dir="ltr" /></label>
|
||||||
@@ -1684,6 +1692,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
|||||||
DRIVER_BIRTH_DAY:bd.d,
|
DRIVER_BIRTH_DAY:bd.d,
|
||||||
DRIVER_IS_INSURER:q("DRIVER_IS_INSURER"),
|
DRIVER_IS_INSURER:q("DRIVER_IS_INSURER"),
|
||||||
DRIVER_IS_OWNER:q("DRIVER_IS_OWNER"),
|
DRIVER_IS_OWNER:q("DRIVER_IS_OWNER"),
|
||||||
|
PERSON_ROLE_ID:q("PERSON_ROLE_ID"),
|
||||||
DRIVER_MOBILE:q("DRIVER_MOBILE"),
|
DRIVER_MOBILE:q("DRIVER_MOBILE"),
|
||||||
DRIVER_TEL:q("DRIVER_TEL"),
|
DRIVER_TEL:q("DRIVER_TEL"),
|
||||||
DRIVER_ADDRESS:q("DRIVER_ADDRESS"),
|
DRIVER_ADDRESS:q("DRIVER_ADDRESS"),
|
||||||
@@ -1819,12 +1828,11 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
|||||||
$("EXPERTISE_CLAIM_EXPERT_ID").closest("label").querySelector("b").textContent = hull ? "GEN.06 ClaimExpertId" : "GEN.08 ExpertiseClaimExpertId";
|
$("EXPERTISE_CLAIM_EXPERT_ID").closest("label").querySelector("b").textContent = hull ? "GEN.06 ClaimExpertId" : "GEN.08 ExpertiseClaimExpertId";
|
||||||
$("stageNotification").hidden = hull || q("FANAVARAN_API_VERSION") !== "v15";
|
$("stageNotification").hidden = hull || q("FANAVARAN_API_VERSION") !== "v15";
|
||||||
$("formTabNotify").hidden = hull || (q("FANAVARAN_API_VERSION") !== "v15" && q("FANAVARAN_CLIENT") !== "moallem");
|
$("formTabNotify").hidden = hull || (q("FANAVARAN_API_VERSION") !== "v15" && q("FANAVARAN_CLIENT") !== "moallem");
|
||||||
document.querySelector('[data-form-panel="person"]').hidden = hull;
|
document.querySelector('[data-form-tab="person"]').hidden = false;
|
||||||
document.querySelector('[data-form-tab="person"]').hidden = hull;
|
|
||||||
if (hull && document.querySelector('[data-form-tab="person"]')?.classList.contains("active")) showFormTab("cars");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function missingRequiredNotifier(stage) {
|
function missingRequiredNotifier(stage) {
|
||||||
|
if (stage === "auth" || stage === "person") return "";
|
||||||
if (q("FANAVARAN_PRODUCT") === "CAR_BODY") return "";
|
if (q("FANAVARAN_PRODUCT") === "CAR_BODY") return "";
|
||||||
const v15 = q("FANAVARAN_API_VERSION") === "v15";
|
const v15 = q("FANAVARAN_API_VERSION") === "v15";
|
||||||
const moallemV14 = q("FANAVARAN_CLIENT") === "moallem" && !v15;
|
const moallemV14 = q("FANAVARAN_CLIENT") === "moallem" && !v15;
|
||||||
@@ -2025,6 +2033,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
|||||||
}
|
}
|
||||||
set("DRIVER_IS_INSURER","DRIVER_IS_INSURER");
|
set("DRIVER_IS_INSURER","DRIVER_IS_INSURER");
|
||||||
set("DRIVER_IS_OWNER","DRIVER_IS_OWNER");
|
set("DRIVER_IS_OWNER","DRIVER_IS_OWNER");
|
||||||
|
set("PERSON_ROLE_ID","PERSON_ROLE_ID");
|
||||||
set("DRIVER_MOBILE","DRIVER_MOBILE");
|
set("DRIVER_MOBILE","DRIVER_MOBILE");
|
||||||
set("DRIVER_TEL","DRIVER_TEL");
|
set("DRIVER_TEL","DRIVER_TEL");
|
||||||
set("DRIVER_ADDRESS","DRIVER_ADDRESS");
|
set("DRIVER_ADDRESS","DRIVER_ADDRESS");
|
||||||
@@ -2323,6 +2332,12 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
|||||||
setStatus("سرور UI روشن نیست.", "err");
|
setStatus("سرور UI روشن نیست.", "err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (stage === "person" && q("PERSON_ROLE_ID") !== "166") {
|
||||||
|
setStatus("نقش مورد نظر را انتخاب کنید. این فرم ثبت نقش سایر (166) را پشتیبانی میکند.", "err");
|
||||||
|
showFormTab("person");
|
||||||
|
$("PERSON_ROLE_ID").focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (q("FANAVARAN_PRODUCT") !== "CAR_BODY" && q("CULPRIT_TYPE_ID")==="338" && !q("ACCIDENT_CULPRIT_ID") && (stage==="base"||stage==="all")) {
|
if (q("FANAVARAN_PRODUCT") !== "CAR_BODY" && q("CULPRIT_TYPE_ID")==="338" && !q("ACCIDENT_CULPRIT_ID") && (stage==="base"||stage==="all")) {
|
||||||
setStatus("ACCIDENT_CULPRIT_ID برای CulpritTypeId=338 لازم است.", "err");
|
setStatus("ACCIDENT_CULPRIT_ID برای CulpritTypeId=338 لازم است.", "err");
|
||||||
return;
|
return;
|
||||||
@@ -2408,6 +2423,11 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
|||||||
body: JSON.stringify({ stage, env, ui: collectUi() }),
|
body: JSON.stringify({ stage, env, ui: collectUi() }),
|
||||||
});
|
});
|
||||||
if (result.ids) Object.assign(stateIds, result.ids);
|
if (result.ids) Object.assign(stateIds, result.ids);
|
||||||
|
if (result.ok && stage === "person" && q("FANAVARAN_PRODUCT") === "CAR_BODY" && result.ids?.ACCIDENT_CULPRIT_ID) {
|
||||||
|
setComboValue("ACCIDENT_CULPRIT_ID", result.ids.ACCIDENT_CULPRIT_ID, {
|
||||||
|
id: result.ids.ACCIDENT_CULPRIT_ID, caption: "راننده ثبتشده با نقش سایر",
|
||||||
|
});
|
||||||
|
}
|
||||||
renderIds();
|
renderIds();
|
||||||
const snap = snapshot();
|
const snap = snapshot();
|
||||||
persistLocal(snap);
|
persistLocal(snap);
|
||||||
|
|||||||
@@ -812,7 +812,8 @@ inquire_hull_policy_vehicle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inquire_driver_id() {
|
inquire_driver_id() {
|
||||||
if [[ -n "${DRIVER_ID:-}" ]]; then
|
local required_role="${1:-}"
|
||||||
|
if [[ -n "${DRIVER_ID:-}" && "$required_role" != "166" ]] && ! is_car_body; then
|
||||||
ok "Using DRIVER_ID=$DRIVER_ID from env (skip inquiry)"
|
ok "Using DRIVER_ID=$DRIVER_ID from env (skip inquiry)"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -830,14 +831,14 @@ inquire_driver_id() {
|
|||||||
fv_curl_json GET "$url" "$out"
|
fv_curl_json GET "$url" "$out"
|
||||||
|
|
||||||
local target_role=166
|
local target_role=166
|
||||||
if [[ "$DRIVER_IS_INSURER" == "1" || "${DRIVER_IS_INSURER,,}" == "true" ]]; then
|
if [[ "$required_role" != "166" ]] && ! is_car_body && [[ "$DRIVER_IS_INSURER" == "1" || "${DRIVER_IS_INSURER,,}" == "true" ]]; then
|
||||||
target_role=161
|
target_role=161
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DRIVER_ID="$(node -e '
|
DRIVER_ID="$(node -e '
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const target = Number(process.argv[2]);
|
const target = Number(process.argv[2]);
|
||||||
const ACCEPTED = new Set([161, 166]);
|
const ACCEPTED = new Set(process.argv[3] === "CAR_BODY" || process.argv[4] === "166" ? [166] : [161, 166]);
|
||||||
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
||||||
const rows = Array.isArray(data) ? data : (data?.value || data?.data || []);
|
const rows = Array.isArray(data) ? data : (data?.value || data?.data || []);
|
||||||
if (!Array.isArray(rows) || !rows.length) { console.log(""); process.exit(0); }
|
if (!Array.isArray(rows) || !rows.length) { console.log(""); process.exit(0); }
|
||||||
@@ -846,20 +847,21 @@ if (match && Number(match.Id) > 0) { console.log(String(match.Id)); process.exit
|
|||||||
const accepted = rows.find(r => ACCEPTED.has(Number(r.RoleId)) && Number(r.Id) > 0);
|
const accepted = rows.find(r => ACCEPTED.has(Number(r.RoleId)) && Number(r.Id) > 0);
|
||||||
if (accepted) console.log(String(accepted.Id));
|
if (accepted) console.log(String(accepted.Id));
|
||||||
else console.log("");
|
else console.log("");
|
||||||
' "$out" "$target_role")"
|
' "$out" "$target_role" "$FANAVARAN_PRODUCT" "$required_role")"
|
||||||
|
|
||||||
if [[ -n "$DRIVER_ID" ]]; then
|
if [[ -n "$DRIVER_ID" ]]; then
|
||||||
ok "DriverId=$DRIVER_ID (inquiry RoleId=$target_role or accepted 161/166)"
|
ok "DriverId=$DRIVER_ID (verified acceptable role; target RoleId=$target_role)"
|
||||||
persist_env DRIVER_ID
|
persist_env DRIVER_ID
|
||||||
save_ids
|
save_ids
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
warn "Driver inquiry has no RoleId 161/166 for $DRIVER_NATIONAL_CODE — GEN.44 other-people create"
|
warn "Driver inquiry has no acceptable role for $DRIVER_NATIONAL_CODE — GEN.44 other-people create"
|
||||||
create_other_person
|
create_other_person "$required_role"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_other_person() {
|
create_other_person() {
|
||||||
|
local required_role="${1:-}"
|
||||||
require_var DRIVER_NATIONAL_CODE
|
require_var DRIVER_NATIONAL_CODE
|
||||||
require_var DRIVER_BIRTH_YEAR
|
require_var DRIVER_BIRTH_YEAR
|
||||||
require_var DRIVER_BIRTH_MONTH
|
require_var DRIVER_BIRTH_MONTH
|
||||||
@@ -956,7 +958,7 @@ NODE
|
|||||||
|
|
||||||
DRIVER_ID="$(node -e '
|
DRIVER_ID="$(node -e '
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const ACCEPTED = new Set([161, 166]);
|
const ACCEPTED = new Set(process.argv[2] === "CAR_BODY" || process.argv[3] === "166" ? [166] : [161, 166]);
|
||||||
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
||||||
const rows = Array.isArray(data) ? data : (data?.value || data?.data || []);
|
const rows = Array.isArray(data) ? data : (data?.value || data?.data || []);
|
||||||
const accepted = Array.isArray(rows)
|
const accepted = Array.isArray(rows)
|
||||||
@@ -964,9 +966,9 @@ const accepted = Array.isArray(rows)
|
|||||||
: null;
|
: null;
|
||||||
if (accepted) console.log(String(accepted.Id));
|
if (accepted) console.log(String(accepted.Id));
|
||||||
else console.log("");
|
else console.log("");
|
||||||
' "$retry")"
|
' "$retry" "$FANAVARAN_PRODUCT" "$required_role")"
|
||||||
|
|
||||||
if [[ -z "$DRIVER_ID" && -n "${OTHER_PERSON_ID:-}" ]]; then
|
if [[ -z "$DRIVER_ID" && -n "${OTHER_PERSON_ID:-}" && "$required_role" != "166" ]] && ! is_car_body; then
|
||||||
DRIVER_ID="$OTHER_PERSON_ID"
|
DRIVER_ID="$OTHER_PERSON_ID"
|
||||||
warn "Re-inquiry still empty — using GEN.44 Id as DriverId=$DRIVER_ID"
|
warn "Re-inquiry still empty — using GEN.44 Id as DriverId=$DRIVER_ID"
|
||||||
fi
|
fi
|
||||||
@@ -1644,10 +1646,20 @@ info "Fanavaran-only flow | client=$FANAVARAN_CLIENT | api=$API_VERSION_LABEL |
|
|||||||
info "Env file (section B will be updated in-place): $ENV_FILE"
|
info "Env file (section B will be updated in-place): $ENV_FILE"
|
||||||
info "Output: $OUT_DIR"
|
info "Output: $OUT_DIR"
|
||||||
|
|
||||||
|
if stage_wanted person; then
|
||||||
|
[[ "${PERSON_ROLE_ID:-}" == "166" ]] || die "Select PERSON_ROLE_ID=166 (سایر). GEN.44 does not register arbitrary roles."
|
||||||
|
fi
|
||||||
|
|
||||||
fanavaran_login
|
fanavaran_login
|
||||||
|
|
||||||
if stage_wanted person && ! is_car_body; then
|
if stage_wanted person; then
|
||||||
inquire_driver_id
|
info "Person registration requested: RoleId=$PERSON_ROLE_ID (سایر); checking live inquiry"
|
||||||
|
inquire_driver_id "$PERSON_ROLE_ID"
|
||||||
|
if is_car_body && [[ -n "${DRIVER_ID:-}" && "$PREVIEW_ONLY" -eq 0 ]]; then
|
||||||
|
ACCIDENT_CULPRIT_ID="$DRIVER_ID"
|
||||||
|
persist_env ACCIDENT_CULPRIT_ID
|
||||||
|
save_ids
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Soft-ensure order like the app: later stages create earlier ones if ids missing
|
# Soft-ensure order like the app: later stages create earlier ones if ids missing
|
||||||
|
|||||||
@@ -786,6 +786,7 @@ function envObjectToText(obj) {
|
|||||||
"DRIVER_BIRTH_DAY",
|
"DRIVER_BIRTH_DAY",
|
||||||
"DRIVER_IS_INSURER",
|
"DRIVER_IS_INSURER",
|
||||||
"DRIVER_IS_OWNER",
|
"DRIVER_IS_OWNER",
|
||||||
|
"PERSON_ROLE_ID",
|
||||||
"DRIVER_MOBILE",
|
"DRIVER_MOBILE",
|
||||||
"DRIVER_TEL",
|
"DRIVER_TEL",
|
||||||
"DRIVER_ADDRESS",
|
"DRIVER_ADDRESS",
|
||||||
|
|||||||
@@ -0,0 +1,139 @@
|
|||||||
|
const assert = require("node:assert/strict");
|
||||||
|
const fs = require("node:fs");
|
||||||
|
const path = require("node:path");
|
||||||
|
const vm = require("node:vm");
|
||||||
|
const { test } = require("node:test");
|
||||||
|
const { spawnSync } = require("node:child_process");
|
||||||
|
const html = fs.readFileSync(path.join(__dirname, "data/fanavaran-flow-ui.html"), "utf8");
|
||||||
|
const shell = fs.readFileSync(path.join(__dirname, "fanavaran-flow-test.sh"), "utf8");
|
||||||
|
|
||||||
|
test("hull selection keeps the registration tab visible and preserves an open registration panel", () => {
|
||||||
|
const tab = { hidden: true, classList: { contains: () => true } };
|
||||||
|
const panel = { hidden: false };
|
||||||
|
const element = { closest: () => ({ querySelector: () => ({}) }) };
|
||||||
|
const context = vm.createContext({
|
||||||
|
q: (id) => id === "FANAVARAN_PRODUCT" ? "CAR_BODY" : "v14",
|
||||||
|
$: () => element,
|
||||||
|
showFormTab: () => assert.fail("switching product must not eject the person tab"),
|
||||||
|
document: {
|
||||||
|
body: { dataset: {} },
|
||||||
|
querySelector: (selector) => selector.includes('panel="person"') ? panel : tab,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const start = html.indexOf(" function syncProduct()");
|
||||||
|
const end = html.indexOf(" function missingRequiredNotifier", start);
|
||||||
|
vm.runInContext(html.slice(start, end) + "\nsyncProduct();", context);
|
||||||
|
assert.equal(tab.hidden, false);
|
||||||
|
assert.equal(panel.hidden, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
function selectDriver(product, rows, afterCreate = false, requiredRole = "") {
|
||||||
|
const start = shell.indexOf(' DRIVER_ID="$(node -e \'', shell.indexOf(afterCreate ? "create_other_person() {" : "inquire_driver_id() {"));
|
||||||
|
const bodyStart = shell.indexOf("\n", start) + 1;
|
||||||
|
const end = shell.indexOf("\n' ", bodyStart);
|
||||||
|
let selected = "";
|
||||||
|
const exited = {};
|
||||||
|
const context = vm.createContext({
|
||||||
|
require: () => ({ readFileSync: () => JSON.stringify(rows) }),
|
||||||
|
process: { argv: afterCreate ? ["node", "fixture", product, requiredRole] : ["node", "fixture", "166", product, requiredRole], exit: () => { throw exited; } },
|
||||||
|
console: { log: (value) => { selected = String(value); } },
|
||||||
|
});
|
||||||
|
try { vm.runInContext(shell.slice(bodyStart, end), context); }
|
||||||
|
catch (error) { if (error !== exited) throw error; }
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const afterCreate of [false, true]) {
|
||||||
|
test(`hull ${afterCreate ? "post-registration verification" : "inquiry"} requires role 166`, () => {
|
||||||
|
assert.equal(selectDriver("CAR_BODY", [{ Id: 41, RoleId: 161 }], afterCreate), "");
|
||||||
|
assert.equal(selectDriver("CAR_BODY", [{ Id: 41, RoleId: 161 }, { Id: 42, RoleId: 166 }], afterCreate), "42");
|
||||||
|
});
|
||||||
|
test(`third-party ${afterCreate ? "verification" : "inquiry"} retains role-161 acceptance`, () => {
|
||||||
|
assert.equal(selectDriver("THIRD_PARTY", [{ Id: 41, RoleId: 161 }], afterCreate), "41");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test("the inline UI script parses", () => {
|
||||||
|
const script = html.match(/<script>([\s\S]*?)<\/script>/)[1];
|
||||||
|
new vm.Script(script);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const [client, version] of [["moallem", "v14"], ["tejaratno", "v15"]]) {
|
||||||
|
test(`${client} ${version}: registering a person does not require claim notifier fields`, () => {
|
||||||
|
const context = vm.createContext({
|
||||||
|
q: (id) => ({ FANAVARAN_PRODUCT: "THIRD_PARTY", FANAVARAN_CLIENT: client,
|
||||||
|
FANAVARAN_API_VERSION: version, CLAIM_NOTIFICATION_DATE: "1405/08/30",
|
||||||
|
NOTIFIER_PARTY_ID: "41" })[id] || "",
|
||||||
|
lookupValue: () => "",
|
||||||
|
stateIds: { CLAIM_ID: "" },
|
||||||
|
});
|
||||||
|
const start = html.indexOf(" function missingRequiredNotifier(stage)");
|
||||||
|
const end = html.indexOf(" function envToText", start);
|
||||||
|
vm.runInContext(html.slice(start, end), context);
|
||||||
|
assert.equal(vm.runInContext('missingRequiredNotifier("person")', context), "");
|
||||||
|
assert.match(vm.runInContext('missingRequiredNotifier("base")', context), /NotifierTypeId/);
|
||||||
|
assert.match(vm.runInContext('missingRequiredNotifier("base")', context), /NotifierRelationId/);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (const afterCreate of [false, true]) {
|
||||||
|
test(`manual person ${afterCreate ? "verification" : "inquiry"} enforces the selected role even in third-party mode`, () => {
|
||||||
|
assert.equal(selectDriver("THIRD_PARTY", [{ Id: 41, RoleId: 161 }], afterCreate, "166"), "");
|
||||||
|
assert.equal(selectDriver("THIRD_PARTY", [{ Id: 41, RoleId: 161 }, { Id: 42, RoleId: 166 }], afterCreate, "166"), "42");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test("manual role-166 registration checks live inquiry despite a cached driver ID", () => {
|
||||||
|
const start = shell.indexOf("inquire_driver_id() {");
|
||||||
|
const end = shell.indexOf("create_other_person() {", start);
|
||||||
|
const script = `set -euo pipefail
|
||||||
|
${shell.slice(start, end)}
|
||||||
|
is_car_body() { return 1; }
|
||||||
|
ask_var() { :; }
|
||||||
|
info() { :; }
|
||||||
|
ok() { :; }
|
||||||
|
warn() { :; }
|
||||||
|
persist_env() { :; }
|
||||||
|
save_ids() { :; }
|
||||||
|
fv_curl_json() { echo LIVE_INQUIRY; }
|
||||||
|
node() { printf 42; }
|
||||||
|
create_other_person() { echo UNEXPECTED_CREATE; }
|
||||||
|
DRIVER_ID=41
|
||||||
|
DRIVER_IS_INSURER=1
|
||||||
|
DRIVER_NATIONAL_CODE=0012345678
|
||||||
|
DRIVER_BIRTH_YEAR=1360
|
||||||
|
DRIVER_BIRTH_MONTH=1
|
||||||
|
DRIVER_BIRTH_DAY=2
|
||||||
|
FANAVARAN_PRODUCT=THIRD_PARTY
|
||||||
|
FANAVARAN_BIME_URL=https://example.invalid
|
||||||
|
OUT_DIR=/tmp
|
||||||
|
inquire_driver_id 166
|
||||||
|
printf 'RESULT=%s' "$DRIVER_ID"
|
||||||
|
`;
|
||||||
|
const result = spawnSync("/bin/bash", ["-c", script], { encoding: "utf8", timeout: 5000 });
|
||||||
|
assert.equal(result.status, 0, result.stderr);
|
||||||
|
assert.match(result.stdout, /LIVE_INQUIRY/);
|
||||||
|
assert.match(result.stdout, /RESULT=42/);
|
||||||
|
assert.doesNotMatch(result.stdout, /UNEXPECTED_CREATE/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the registration button requires an explicit supported role before sending a request", async () => {
|
||||||
|
const notices = [];
|
||||||
|
let focused = false;
|
||||||
|
const context = vm.createContext({
|
||||||
|
busy: false,
|
||||||
|
ping: async () => true,
|
||||||
|
q: () => "",
|
||||||
|
setStatus: (message) => notices.push(message),
|
||||||
|
showFormTab: (name) => assert.equal(name, "person"),
|
||||||
|
$: (id) => { assert.equal(id, "PERSON_ROLE_ID"); return { focus: () => { focused = true; } }; },
|
||||||
|
api: () => assert.fail("registration cannot run before role selection"),
|
||||||
|
});
|
||||||
|
const start = html.indexOf(" async function runStage(stage)");
|
||||||
|
const end = html.indexOf(' $("LOCATION").addEventListener', start);
|
||||||
|
vm.runInContext(html.slice(start, end), context);
|
||||||
|
await vm.runInContext('runStage("person")', context);
|
||||||
|
assert.equal(focused, true);
|
||||||
|
assert.match(notices[0], /166/);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user