forked from Yara724/api
Better error handling and validation and min/max prices added for expert submit
This commit is contained in:
@@ -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,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user