Better error handling and validation and min/max prices added for expert submit

This commit is contained in:
SepehrYahyaee
2026-09-08 13:11:24 +03:30
parent eb6cef1127
commit 0e861ff6d1
9 changed files with 485 additions and 45 deletions

View File

@@ -95,4 +95,45 @@ describe("ExpertClaimService expert-reply pricing", () => {
expect(findByIdAndUpdate).not.toHaveBeenCalled();
});
it("returns a Persian, field-specific error when a V2 price is below the minimum", async () => {
const service = createService() as any;
const findByIdAndUpdate = jest.fn();
service.claimCaseDbService = {
findById: jest.fn().mockResolvedValue({
status: ClaimCaseStatus.EXPERT_REVIEWING,
workflow: { locked: true, lockedBy: { actorId: "expert-1" } },
}),
findByIdAndUpdate,
};
service.assertExpertActorOnClaim = jest.fn().mockResolvedValue(undefined);
await expect(
service.submitExpertReplyV2(
"v2-claim",
{
description: "Damage assessment",
parts: [
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
price: "99,999",
salary: "100000",
totalPayment: "100000",
factorNeeded: false,
},
],
},
{ sub: "expert-1", role: RoleEnum.FIELD_EXPERT },
),
).rejects.toMatchObject({
response: {
code: "EXPERT_REPLY_VALIDATION_ERROR",
field: "parts[0].price",
message: expect.stringContaining("حداقل"),
},
});
expect(findByIdAndUpdate).not.toHaveBeenCalled();
});
});