feat: manage expert access and merge Parsian expert seeds

Allow role-specific identities and admin account activation, support national-code-only claim experts, and remove required voice from v4/v5. Add a combined, resumable Parsian seed that preserves existing accounts and merges locations and product codes.
This commit is contained in:
SepehrYahyaee
2026-11-18 17:16:26 +03:30
parent 2cdbc35d2e
commit 83376df4ad
38 changed files with 3608 additions and 136 deletions
@@ -10,6 +10,133 @@ import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-
import { ClaimWorkflowStep } from "src/Types&Enums/claim-request-management/claim-workflow-steps.enum";
describe("RequestManagementService V4 FileMaker workflow", () => {
it.each([
[4, BlameRequestType.CAR_BODY],
[4, BlameRequestType.THIRD_PARTY],
[5, BlameRequestType.CAR_BODY],
[5, BlameRequestType.THIRD_PARTY],
])(
"completes v%s %s narratives and signatures without voice",
async (flow, type) => {
const actor = {
sub: String(new Types.ObjectId()),
role: RoleEnum.FILE_MAKER,
};
const request: any = {
_id: new Types.ObjectId(),
type,
expertInitiated: true,
isMadeByFileMaker: true,
requiresFileMakerApproval: flow === 5,
initiatedByFieldExpertId: new Types.ObjectId(actor.sub),
creationMethod: CreationMethod.IN_PERSON,
status: CaseStatus.OPEN,
parties: [
PartyRole.FIRST,
...(type === BlameRequestType.THIRD_PARTY ? [PartyRole.SECOND] : []),
].map((role) => ({
role,
person: { userId: new Types.ObjectId() },
evidence: {},
})),
workflow: {
currentStep: WorkflowStep.FIRST_INITIAL_FORM,
completedSteps: [],
},
history: [],
save: jest.fn().mockResolvedValue(undefined),
};
const service: any = new (RequestManagementService as any)();
service.verifyExpertAccessForBlameV2 = jest
.fn()
.mockResolvedValue(undefined);
service.blameRequestDbService = {
findById: async () => request,
findByIdAndUpdate: async (_id, update) => {
for (const [key, value] of Object.entries(update.$set)) {
const [, index] = key.split(".");
request.parties[Number(index)].confirmation = value;
}
},
};
service.userSign = {
create: jest.fn(async () => ({ _id: new Types.ObjectId() })),
};
service.blameVoiceDbService = { create: jest.fn() };
for (const party of request.parties) {
service.markPartyInquiriesCompleteOnBlame(request, party.role, actor);
const prefix = party.role === PartyRole.FIRST ? "FIRST" : "SECOND";
expect(request.workflow.currentStep).toBe(`${prefix}_DESCRIPTION`);
const description = {
desc: "شرح حادثه ".repeat(15),
accidentDate: "2025-01-01",
accidentTime: "10:30",
};
if (flow === 4)
await service.addPartyDescriptionV4(
String(request._id),
actor,
description,
party.role,
);
else
await service.addPartyDescriptionV3(
String(request._id),
actor,
description,
party.role,
);
expect(request.workflow.currentStep).toBe(`${prefix}_SIGN`);
await service.expertUploadPartySignatureV3(
actor,
String(request._id),
party.role,
true,
{ filename: "signature.png", path: "files/signature.png" },
);
expect(party.confirmation.accepted).toBe(true);
expect(request.workflow.completedSteps).not.toContain(
`${prefix}_VOICE`,
);
}
expect(service.blameVoiceDbService.create).not.toHaveBeenCalled();
expect(request.workflow.currentStep).toBe(
type === BlameRequestType.CAR_BODY
? WorkflowStep.FIRST_COMPLETED
: WorkflowStep.SECOND_COMPLETED,
);
},
);
it.each([WorkflowStep.FIRST_VOICE, WorkflowStep.SECOND_VOICE])(
"repairs legacy %s resume values without erasing existing recordings or history",
(step) => {
const service: any = new (RequestManagementService as any)();
const file = {
workflow: {
currentStep: step,
nextStep: step.replace("VOICE", "DESCRIPTION"),
completedSteps: [step],
},
parties: [{ evidence: { voices: ["existing-recording"] } }],
history: [{ type: "V3_PARTY_VOICE_UPLOADED" }],
};
const before = JSON.stringify(file);
expect(service.fileMakerWorkflowProjection(file).currentStep).toBe(
step.replace("VOICE", "DESCRIPTION"),
);
expect(service.fileMakerWorkflowProjection(file).nextStep).toBe(step.replace("VOICE", "SIGN"));
expect(JSON.stringify(file)).toBe(before);
},
);
it("keeps voice in the non-FileMaker in-person inquiry workflow", () => {
const service: any = new (RequestManagementService as any)();
const request: any = { workflow: { completedSteps: [] }, parties: [] };
service.markPartyInquiriesCompleteOnBlame(request, PartyRole.FIRST, {});
expect(request.workflow.currentStep).toBe(WorkflowStep.FIRST_LOCATION);
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_VOICE);
});
it("persists FIRST_INITIAL_FORM after the first party OTP is verified", async () => {
const fileMakerId = new Types.ObjectId();
const userId = new Types.ObjectId();
@@ -87,7 +214,7 @@ describe("RequestManagementService V4 FileMaker workflow", () => {
expect(request.workflow.currentStep).toBe(WorkflowStep.FIRST_INITIAL_FORM);
expect(request.workflow.currentStep).not.toBe(WorkflowStep.FIRST_VIDEO);
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_VOICE);
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_DESCRIPTION);
expect(request.workflow.completedSteps).not.toContain(
WorkflowStep.FIRST_VIDEO,
);
@@ -169,7 +296,7 @@ describe("RequestManagementService V4 FileMaker workflow", () => {
);
expect(request.workflow.currentStep).toBe(WorkflowStep.FIRST_INITIAL_FORM);
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_VOICE);
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_DESCRIPTION);
expect(request.workflow.completedSteps).not.toContain(
WorkflowStep.FIRST_VIDEO,
);
@@ -212,7 +339,7 @@ describe("RequestManagementService V4 FileMaker workflow", () => {
expect(reopened.workflow).toEqual(
expect.objectContaining({
currentStep: WorkflowStep.FIRST_INITIAL_FORM,
nextStep: WorkflowStep.FIRST_VOICE,
nextStep: WorkflowStep.FIRST_DESCRIPTION,
}),
);
expect(reopened.workflow.completedSteps).not.toContain(