Removed some validations that were unneccesary for expert submit

This commit is contained in:
SepehrYahyaee
2026-09-06 12:09:34 +03:30
parent 233a16d96c
commit c9b5b6f765
5 changed files with 74 additions and 43 deletions

View File

@@ -47,7 +47,7 @@ describe("getExpertReplyPricingValidationError", () => {
).toBeNull();
});
it("rejects a repair line without a price", () => {
it("accepts a repair line without a price", () => {
expect(
getExpertReplyPricingValidationError([
{
@@ -55,10 +55,9 @@ describe("getExpertReplyPricingValidationError", () => {
typeOfDamage: TypeOfDamage.Repair,
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toMatch(/price is also required/);
).toBeNull();
});
it("rejects recycled-value daghi without its price", () => {
@@ -67,6 +66,7 @@ describe("getExpertReplyPricingValidationError", () => {
{
partId: 201,
typeOfDamage: TypeOfDamage.Change,
price: "0",
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.RECYCLED_PARTS_VALUE },
@@ -75,7 +75,7 @@ describe("getExpertReplyPricingValidationError", () => {
).toMatch(/requires a valid daghi price/);
});
it("accepts a replacement line without a part price", () => {
it("rejects a replacement line without a part price", () => {
expect(
getExpertReplyPricingValidationError([
{
@@ -86,7 +86,7 @@ describe("getExpertReplyPricingValidationError", () => {
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toBeNull();
).toMatch(/price is also required/);
});
it("rejects an invalid price when a replacement line supplies one", () => {
@@ -103,4 +103,22 @@ describe("getExpertReplyPricingValidationError", () => {
]),
).toMatch(/requires valid salary and totalPayment/);
});
it("accepts a recycled-parts daghi price above the repair-line cap", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 23,
typeOfDamage: TypeOfDamage.Change,
price: "۵۰,۰۰۰",
salary: "۱۰۰,۰۰۰",
totalPayment: "150000",
daghi: {
option: DaghiOption.RECYCLED_PARTS_VALUE,
price: "۱۰۰,۵۰۰,۰۰۰",
},
},
]),
).toBeNull();
});
});

View File

@@ -1,4 +1,3 @@
import { REPAIR_LINE_AMOUNT_TOMAN } from "src/constants/repair-amount-limits";
import { DaghiOption } from "src/Types&Enums/claim-request-management/daghi-option.enum";
import { TypeOfDamage } from "src/Types&Enums/claim-request-management/type-of-damage.enum";
import { parseMoneyAmountToman } from "src/utils/unicode-digits";
@@ -59,33 +58,22 @@ export function getExpertReplyPricingValidationError(
part.price != null &&
(typeof part.price !== "string" || part.price.trim() !== "");
const splitAmountIsValid = (amount: number | null) =>
amount !== null &&
(amount === 0 ||
(amount >= REPAIR_LINE_AMOUNT_TOMAN.MIN &&
amount <= REPAIR_LINE_AMOUNT_TOMAN.MAX));
const totalIsValid =
totalPayment !== null &&
totalPayment >= 0 &&
totalPayment <= REPAIR_LINE_AMOUNT_TOMAN.MAX;
const priceIsRequired = part.typeOfDamage === TypeOfDamage.Repair;
const priceIsValid =
!hasPrice || (price !== null && splitAmountIsValid(price));
const amountIsValid = (amount: number | null) => amount !== null;
const priceIsRequired = part.typeOfDamage === TypeOfDamage.Change;
const priceIsValid = !hasPrice || amountIsValid(price);
if (
!splitAmountIsValid(salary) ||
!totalIsValid ||
(priceIsRequired && !splitAmountIsValid(price)) ||
!amountIsValid(salary) ||
!amountIsValid(totalPayment) ||
(priceIsRequired && !amountIsValid(price)) ||
!priceIsValid
) {
return `${label} requires valid salary and totalPayment; price is also required for '${TypeOfDamage.Repair}' damage. Price and salary may be 0; totalPayment may be 0.`;
return `${label} requires valid salary and totalPayment; price is also required for '${TypeOfDamage.Change}' damage. Price, salary, and totalPayment may be 0.`;
}
if (
daghi?.option === DaghiOption.RECYCLED_PARTS_VALUE &&
(daghiPrice === null ||
daghiPrice < REPAIR_LINE_AMOUNT_TOMAN.MIN ||
daghiPrice > REPAIR_LINE_AMOUNT_TOMAN.MAX)
daghiPrice === null
) {
return `${label} requires a valid daghi price when option is '${DaghiOption.RECYCLED_PARTS_VALUE}'.`;
}