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
+42 -1
View File
@@ -1,4 +1,8 @@
import { getExpertReplyPricingValidationError } from "./expert-reply-pricing";
import {
EXPERT_REPLY_MAX_AMOUNT_TOMAN,
EXPERT_REPLY_MIN_AMOUNT_TOMAN,
getExpertReplyPricingValidationError,
} from "./expert-reply-pricing";
import { TypeOfDamage } from "src/Types&Enums/claim-request-management/type-of-damage.enum";
import { DaghiOption } from "src/Types&Enums/claim-request-management/daghi-option.enum";
@@ -121,4 +125,41 @@ describe("getExpertReplyPricingValidationError", () => {
]),
).toBeNull();
});
it.each([
["price", "99,999", "parts[0].price"],
["salary", "10,000,000,001", "parts[0].salary"],
["totalPayment", "99,999", "parts[0].totalPayment"],
["daghi.price", "10,000,000,001", "parts[0].daghi.price"],
])(
"enforces the amount range for %s",
(field, invalidValue, expectedField) => {
const part = {
partId: 201,
typeOfDamage: TypeOfDamage.Change,
price: "100000",
salary: "100000",
totalPayment: "100000",
daghi: {
option: DaghiOption.RECYCLED_PARTS_VALUE,
price: "100000",
},
};
if (field === "daghi.price") part.daghi.price = invalidValue;
else part[field] = invalidValue;
expect(
getExpertReplyPricingValidationError([part], {
locale: "fa",
enforceAmountBounds: true,
}),
).toMatchObject({
code: "EXPERT_REPLY_VALIDATION_ERROR",
field: expectedField,
rule: "amount_out_of_range",
minAmount: EXPERT_REPLY_MIN_AMOUNT_TOMAN,
maxAmount: EXPERT_REPLY_MAX_AMOUNT_TOMAN,
});
},
);
});