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: "باید مبلغ صحیح و غیرمنفی به تومان باشد.", }, ]), }, }); }); });