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

@@ -0,0 +1,70 @@
import { SubmitExpertReplyV2Dto } from "../dto/expert-claim-v2.dto";
import { TypeOfDamage } from "src/Types&Enums/claim-request-management/type-of-damage.enum";
import { submitExpertReplyValidationPipe } from "./submit-expert-reply-validation.pipe";
describe("submitExpertReplyValidationPipe", () => {
it("converts DTO validation failures into Persian, field-addressable errors", async () => {
await expect(
submitExpertReplyValidationPipe.transform(
{ parts: [] },
{ type: "body", metatype: SubmitExpertReplyV2Dto },
),
).rejects.toMatchObject({
response: {
code: "EXPERT_REPLY_VALIDATION_ERROR",
message: "اطلاعات ارسالی پاسخ کارشناسی معتبر نیست.",
validationErrors: expect.arrayContaining([
expect.objectContaining({ field: "parts" }),
]),
},
});
});
it("accepts a reply without a description", async () => {
await expect(
submitExpertReplyValidationPipe.transform(
{
parts: [
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
salary: "100000",
totalPayment: "100000",
factorNeeded: false,
},
],
},
{ type: "body", metatype: SubmitExpertReplyV2Dto },
),
).resolves.toBeInstanceOf(SubmitExpertReplyV2Dto);
});
it("identifies invalid nested price fields for the frontend", async () => {
await expect(
submitExpertReplyValidationPipe.transform(
{
description: "Damage assessment",
parts: [
{
partId: 201,
typeOfDamage: "repair",
salary: "not-a-number",
totalPayment: "100000",
factorNeeded: false,
},
],
},
{ type: "body", metatype: SubmitExpertReplyV2Dto },
),
).rejects.toMatchObject({
response: {
validationErrors: expect.arrayContaining([
{
field: "parts[0].salary",
message: "باید مبلغ صحیح و غیرمنفی به تومان باشد.",
},
]),
},
});
});
});