forked from Yara724/api
feat: route user claims by branch and align licence issue dates
Require the damaged party in user flows to select an active insurer branch and preserve branch access rules. Accept older licence issue dates, correct anniversary boundaries, and update Fanavaran audit documentation and regression coverage.
This commit is contained in:
@@ -55,6 +55,7 @@ function serviceFor(blame: any): any {
|
||||
findOne: jest.fn().mockResolvedValue(null),
|
||||
create: jest.fn().mockResolvedValue({ _id: claimId }),
|
||||
};
|
||||
service.userClaimBranchService = { validate: jest.fn().mockResolvedValue("650000000000000000000099") };
|
||||
service.userDbService = { findAllByPhone: jest.fn().mockResolvedValue([]) };
|
||||
service.generateUniqueClaimNumber = jest.fn().mockResolvedValue("C100");
|
||||
service.autoSubmitToFanavaranV2OnClaimCreated = jest
|
||||
@@ -260,4 +261,18 @@ describe("claim beneficiary authorization across shared user flows", () => {
|
||||
service.assertEffectiveUserIsDamagedPartyOnClaim(claim, effectiveId),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
it("copies the validated branch into the claim and blocks creation when branch validation fails", async () => {
|
||||
const blame = source();
|
||||
blame.branchId = "650000000000000000000099";
|
||||
const service = serviceFor(blame);
|
||||
await service.createClaimFromBlameV2(blameId, secondId);
|
||||
expect(service.userClaimBranchService.validate).toHaveBeenCalledWith(blame, blame.branchId);
|
||||
expect(String(service.claimCaseDbService.create.mock.calls[0][0].branchId)).toBe(blame.branchId);
|
||||
const blocked = serviceFor(source());
|
||||
blocked.userClaimBranchService.validate.mockRejectedValue(new BadRequestException("شعبه را انتخاب کنید"));
|
||||
await expect(blocked.createClaimFromBlameV2(blameId, secondId)).rejects.toBeInstanceOf(BadRequestException);
|
||||
expect(blocked.claimCaseDbService.create).not.toHaveBeenCalled();
|
||||
expect(blocked.autoSubmitToFanavaranV2OnClaimCreated).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { UserClaimBranchService, usesUserClaimBranch } from "src/client/user-claim-branch.service";
|
||||
import {
|
||||
hasReviewedTejaratNotifier,
|
||||
isTejaratNotifierLookup,
|
||||
@@ -505,6 +506,7 @@ export class ClaimRequestManagementService {
|
||||
private readonly claimFactorsImageDbService: ClaimFactorsImageDbService,
|
||||
|
||||
private readonly branchDbService: BranchDbService,
|
||||
private readonly userClaimBranchService: UserClaimBranchService,
|
||||
private readonly claimRequiredDocumentDbService: ClaimRequiredDocumentDbService,
|
||||
|
||||
private readonly sandHubService: SandHubService,
|
||||
@@ -8147,6 +8149,10 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
const selectedBranchId = usesUserClaimBranch(blameRequest)
|
||||
? await this.userClaimBranchService.validate(blameRequest, (blameRequest as any).branchId?.toString())
|
||||
: (blameRequest as any).branchId?.toString();
|
||||
|
||||
// 7. Generate claim number
|
||||
const claimNo = await this.generateUniqueClaimNumber();
|
||||
|
||||
@@ -8163,6 +8169,7 @@ export class ClaimRequestManagementService {
|
||||
publicId: blameRequest.publicId,
|
||||
blameRequestId: new Types.ObjectId(blameRequestId),
|
||||
blameRequestNo: blameRequest.requestNo,
|
||||
...(selectedBranchId ? { branchId: new Types.ObjectId(selectedBranchId) } : {}),
|
||||
status: ClaimCaseStatus.SELECTING_OUTER_PARTS,
|
||||
claimStatus: ClaimStatus.PENDING,
|
||||
inquiries: (blameRequest as any).inquiries ?? {},
|
||||
|
||||
@@ -304,7 +304,7 @@ export class ClaimCase {
|
||||
@Prop({ type: Types.ObjectId, index: true })
|
||||
initiatedByFieldExpertId?: Types.ObjectId;
|
||||
|
||||
/** Branch snapshot inherited from the originating expert-created blame. */
|
||||
/** Routing branch inherited from the blame (user selection or expert-created branch). */
|
||||
@Prop({ type: Types.ObjectId, index: true })
|
||||
branchId?: Types.ObjectId;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ function setup(accessories: unknown) {
|
||||
"vehicle-hull-dmg-cost-kinds": [
|
||||
{ Id: 8002, Caption: "مجموع لوازم", IsActive: 1 },
|
||||
],
|
||||
"car-components": [{ Id: 9 }, { Id: 13 }],
|
||||
"car-components": [{ Id: 9 }, { Id: 13 }, { Id: 112 }],
|
||||
})[name] ?? [],
|
||||
);
|
||||
service.fanavaranLookupService = {
|
||||
@@ -34,6 +34,7 @@ function setup(accessories: unknown) {
|
||||
priceDropTotal: 0,
|
||||
priceDropCarPrice: null,
|
||||
warnings: [],
|
||||
infoWarnings: [],
|
||||
});
|
||||
return { service, build };
|
||||
}
|
||||
@@ -76,16 +77,17 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
AccessoryDesc: "کليه قطعات فابريک",
|
||||
},
|
||||
]);
|
||||
const { payload, warnings } = await build();
|
||||
const { payload, warnings, infoWarnings } = await build();
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([3061139, 3061139]);
|
||||
expect(payload.DmgSections.map((row: any) => row.AccessoryKindId)).toEqual([
|
||||
9, 13,
|
||||
112, 112,
|
||||
]);
|
||||
expect(warnings).toEqual(
|
||||
expect(warnings).toEqual([]);
|
||||
expect(infoWarnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("using factory bundle VehicleHullAccessoryId=3061139"),
|
||||
expect.stringContaining("mapped to factory bundle VehicleHullAccessoryId=3061139 AccessoryKindId=112"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@ describe("fanavaran hull base claim", () => {
|
||||
|
||||
expect(hull.PolicyId).toBe(13764408);
|
||||
expect(hull.AccidentTypeId).toBeNull();
|
||||
expect(hull.IsLicenseReplaced).toBeNull();
|
||||
expect(hull.IsLicenseReplaced).toBe(0);
|
||||
expect(hull.CostSeparationToDmgSections).toBe(0);
|
||||
expect(hull.IsOwnerChanged).toBe(0);
|
||||
expect(hull.CulpritTypeId).toBeNull();
|
||||
|
||||
@@ -125,7 +125,7 @@ export function toFanavaranHullBaseClaimPayload(
|
||||
const next: Record<string, unknown> = {};
|
||||
for (const key of FANAVARAN_HULL_BASE_CLAIM_KEYS) {
|
||||
if (key === "IsLicenseReplaced") {
|
||||
// Fanavaran conditional: >10y since issue → 1; else null (never 0).
|
||||
// Preserve the server's conditional 0 / null / 1 mapping for licence age.
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(built, key) &&
|
||||
(built[key] === 1 || built[key] === 0 || built[key] === null)
|
||||
|
||||
@@ -74,7 +74,7 @@ describe("fanavaran-party-roles", () => {
|
||||
expect(resolveFanavaranLicenceIssuDate(driver)).toBe(
|
||||
FANAVARAN_DUMMY_LICENCE_ISSU_DATE,
|
||||
);
|
||||
expect(FANAVARAN_DUMMY_LICENCE_ISSU_DATE).toBe("1404/08/20");
|
||||
expect(FANAVARAN_DUMMY_LICENCE_ISSU_DATE).toBe("1400/01/01");
|
||||
});
|
||||
|
||||
it("marks licence replaced only when issue date is more than 10 years before accident", () => {
|
||||
@@ -86,7 +86,19 @@ describe("fanavaran-party-roles", () => {
|
||||
).toBeNull();
|
||||
expect(
|
||||
resolveFanavaranIsLicenseReplaced("1404/08/20", "1405/08/20"),
|
||||
).toBeNull();
|
||||
).toBe(0);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["1402/08/21", 0],
|
||||
["1402/08/20", 0],
|
||||
["1402/08/19", null],
|
||||
["1395/08/21", null],
|
||||
["1395/08/20", null],
|
||||
["1395/08/19", 1],
|
||||
["1380/08/20", 1],
|
||||
])("uses the exact anniversary for issue date %s", (issueDate, expected) => {
|
||||
expect(resolveFanavaranIsLicenseReplaced(issueDate, "1405/08/20")).toBe(expected);
|
||||
});
|
||||
|
||||
it("marks DriverIsOwner false when driver and owner differ", () => {
|
||||
|
||||
@@ -35,14 +35,11 @@ export function isJalaliDateOlderThanYears(
|
||||
const issue = parseJalaliDateParts(issueDate);
|
||||
const reference = parseJalaliDateParts(referenceDate);
|
||||
if (!issue || !reference) return false;
|
||||
let age = reference.year - issue.year;
|
||||
if (
|
||||
reference.month < issue.month ||
|
||||
(reference.month === issue.month && reference.day < issue.day)
|
||||
) {
|
||||
age -= 1;
|
||||
}
|
||||
return age > years;
|
||||
const anniversary =
|
||||
(issue.year + years) * 10000 + issue.month * 100 + issue.day;
|
||||
const referenceDay =
|
||||
reference.year * 10000 + reference.month * 100 + reference.day;
|
||||
return referenceDay > anniversary;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user