Add TejaratNo notifier review and submission validation

This commit is contained in:
SepehrYahyaee
2026-10-10 12:51:11 +03:30
parent a410655faa
commit 8f568f379c
14 changed files with 588 additions and 34 deletions
+90
View File
@@ -0,0 +1,90 @@
import { BadRequestException } from "@nestjs/common";
import { LookupsService } from "src/lookups/lookups.service";
import { toFanavaranHullBaseClaimPayload } from "src/claim-request-management/fanavaran-hull-base-claim";
import {
hasReviewedTejaratNotifier,
tejaratNotifierLookup,
} from "./tejarat-notifier";
describe("TejaratNo notifier contract", () => {
it.each(["notifier-type", "notifier-relation"])(
"exposes the supplied %s without querying Fanavaran or the database",
async (name) => {
const service = Object.create(LookupsService.prototype) as any;
service.activeClientKey = jest.fn().mockReturnValue("tejaratno");
service.fanavaranLookupService = { getRemoteLookup: jest.fn() };
service.lookupDbService = { findOne: jest.fn() };
const result = await service.getClientRemoteLookup(name);
expect(result).toEqual(tejaratNotifierLookup(name));
expect(result.every((row) => row.IsActive === 1 && row.Id !== 5518)).toBe(
true,
);
expect(
service.fanavaranLookupService.getRemoteLookup,
).not.toHaveBeenCalled();
expect(service.lookupDbService.findOne).not.toHaveBeenCalled();
},
);
it.each(["parsian", "moallem"])(
"rejects the tenant-specific lookups for %s",
async (clientKey) => {
const service = Object.create(LookupsService.prototype) as any;
service.activeClientKey = jest.fn().mockReturnValue(clientKey);
await expect(
service.getClientRemoteLookup("notifier-type"),
).rejects.toBeInstanceOf(BadRequestException);
},
);
it("does not expose prototype properties as lookup lists", () => {
expect(tejaratNotifierLookup("__proto__")).toBeUndefined();
expect(tejaratNotifierLookup("toString")).toBeUndefined();
});
it("requires explicit, allowed numeric choices only for TejaratNo", () => {
expect(hasReviewedTejaratNotifier(undefined, "parsian")).toBe(true);
expect(hasReviewedTejaratNotifier(undefined, "moallem")).toBe(true);
expect(hasReviewedTejaratNotifier(undefined, "tejaratno")).toBe(false);
expect(
hasReviewedTejaratNotifier({ NotifierTypeId: 5516 }, "tejaratno"),
).toBe(false);
expect(
hasReviewedTejaratNotifier(
{ NotifierTypeId: 5518, NotifierRelationId: 5519 },
"tejaratno",
),
).toBe(false);
expect(
hasReviewedTejaratNotifier(
{ NotifierTypeId: "5516", NotifierRelationId: 5519 },
"tejaratno",
),
).toBe(false);
expect(
hasReviewedTejaratNotifier(
{ NotifierTypeId: 5517, NotifierRelationId: 5526 },
"tejaratno",
),
).toBe(true);
});
it("preserves notifier fields in TejaratNo hull payloads without adding them for other tenants", () => {
const input = {
PolicyId: 12,
NotifierTypeId: 5516,
NotifierRelationId: 5521,
};
expect(toFanavaranHullBaseClaimPayload(input, "tejaratno")).toMatchObject(
input,
);
for (const tenant of ["parsian", "moallem"] as const) {
const payload = toFanavaranHullBaseClaimPayload(input, tenant);
expect(payload).not.toHaveProperty("NotifierTypeId");
expect(payload).not.toHaveProperty("NotifierRelationId");
}
expect(
toFanavaranHullBaseClaimPayload({ PolicyId: 12 }, "tejaratno"),
).not.toHaveProperty("NotifierTypeId");
});
});
+43
View File
@@ -0,0 +1,43 @@
import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
/** Tenant-supplied codebooks. No unverified remote lookup paths or inferred IDs. */
export const TEJARAT_NOTIFIER_LOOKUPS = {
"notifier-type": [
{ Caption: "آسيب ديده", Id: 5516, IsActive: 1 },
{ Caption: "مقصر حادثه", Id: 5517, IsActive: 1 },
],
"notifier-relation": [
{ Caption: "آسيب ديده", Id: 5519, IsActive: 1 },
{ Caption: "نماينده آسيب ديده", Id: 5520, IsActive: 1 },
{ Caption: "مالک", Id: 5521, IsActive: 1 },
{ Caption: "بيمه گذار", Id: 5522, IsActive: 1 },
{ Caption: "راننده", Id: 5523, IsActive: 1 },
{ Caption: "نماينده راننده", Id: 5524, IsActive: 1 },
{ Caption: "نماينده بيمه گذار", Id: 5525, IsActive: 1 },
{ Caption: "نماينده مالک", Id: 5526, IsActive: 1 },
],
} as const;
export const TEJARAT_NOTIFIER_FIELDS = {
NotifierTypeId: "notifier-type",
NotifierRelationId: "notifier-relation",
} as const;
export function tejaratNotifierLookup(name: string) {
if (!Object.prototype.hasOwnProperty.call(TEJARAT_NOTIFIER_LOOKUPS, name))
return undefined;
return TEJARAT_NOTIFIER_LOOKUPS[
name as keyof typeof TEJARAT_NOTIFIER_LOOKUPS
].map((row) => ({ ...row }));
}
/** Both selections must be explicit, canonical numeric IDs; 5518 is excluded. */
export function hasReviewedTejaratNotifier(
values: Record<string, unknown> | null | undefined,
clientKey: FanavaranClientKey,
): boolean {
if (clientKey !== "tejaratno") return true;
return Object.entries(TEJARAT_NOTIFIER_FIELDS).every(([key, lookup]) =>
TEJARAT_NOTIFIER_LOOKUPS[lookup].some((row) => row.Id === values?.[key]),
);
}