forked from Yara724/api
fix(claim-pricing): keep invoice and repair states consistent
This commit is contained in:
@@ -3,6 +3,41 @@ import { TypeOfDamage } from "src/Types&Enums/claim-request-management/type-of-d
|
||||
import { submitExpertReplyValidationPipe } from "./submit-expert-reply-validation.pipe";
|
||||
|
||||
describe("submitExpertReplyValidationPipe", () => {
|
||||
const replacementInvoice = {
|
||||
partId: 201,
|
||||
typeOfDamage: TypeOfDamage.Change,
|
||||
salary: "1000000",
|
||||
totalPayment: "1000000",
|
||||
factorNeeded: true,
|
||||
daghi: { option: "فاقد ارزش" },
|
||||
};
|
||||
|
||||
it("accepts replacement invoices without a numeric part quote", async () => {
|
||||
const result = await submitExpertReplyValidationPipe.transform(
|
||||
{ parts: [replacementInvoice] },
|
||||
{ type: "body", metatype: SubmitExpertReplyV2Dto },
|
||||
);
|
||||
expect(result.parts[0].factorNeeded).toBe(true);
|
||||
expect(result.parts[0].price).toBeUndefined();
|
||||
});
|
||||
|
||||
it.each([{ factorNeeded: false }, { price: "factor" }, { price: "فاکتور" }])(
|
||||
"continues rejecting absent priced quotes and nonnumeric price markers: %j",
|
||||
async (invalid) => {
|
||||
await expect(
|
||||
submitExpertReplyValidationPipe.transform(
|
||||
{ parts: [{ ...replacementInvoice, ...invalid }] },
|
||||
{ type: "body", metatype: SubmitExpertReplyV2Dto },
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
response: {
|
||||
validationErrors: expect.arrayContaining([
|
||||
expect.objectContaining({ field: "parts[0].price" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
it("converts DTO validation failures into Persian, field-addressable errors", async () => {
|
||||
await expect(
|
||||
submitExpertReplyValidationPipe.transform(
|
||||
@@ -61,7 +96,7 @@ describe("submitExpertReplyValidationPipe", () => {
|
||||
validationErrors: expect.arrayContaining([
|
||||
{
|
||||
field: "parts[0].salary",
|
||||
message: "باید مبلغ صحیح و غیرمنفی به تومان باشد.",
|
||||
message: "باید مبلغ صحیح و غیرمنفی به ریال باشد.",
|
||||
},
|
||||
]),
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ const constraintMessages: Record<string, string> = {
|
||||
isInt: "باید یک عدد صحیح باشد.",
|
||||
isEnum: "مقدار واردشده معتبر نیست.",
|
||||
nestedValidation: "اطلاعات این بخش معتبر نیست.",
|
||||
isMoneyAmountString: "باید مبلغ صحیح و غیرمنفی به تومان باشد.",
|
||||
isMoneyAmountString: "باید مبلغ صحیح و غیرمنفی به ریال باشد.",
|
||||
};
|
||||
|
||||
function flattenValidationErrors(
|
||||
@@ -31,11 +31,16 @@ function flattenValidationErrors(
|
||||
? `${parentPath}[${error.property}]`
|
||||
: `${parentPath}.${error.property}`
|
||||
: error.property;
|
||||
const ownErrors = Object.keys(error.constraints ?? {}).map((constraint) => ({
|
||||
field,
|
||||
message: constraintMessages[constraint] ?? "مقدار واردشده معتبر نیست.",
|
||||
}));
|
||||
return [...ownErrors, ...flattenValidationErrors(error.children ?? [], field)];
|
||||
const ownErrors = Object.keys(error.constraints ?? {}).map(
|
||||
(constraint) => ({
|
||||
field,
|
||||
message: constraintMessages[constraint] ?? "مقدار واردشده معتبر نیست.",
|
||||
}),
|
||||
);
|
||||
return [
|
||||
...ownErrors,
|
||||
...flattenValidationErrors(error.children ?? [], field),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user