Files
yara724api/src/helpers/expert-reply-pricing.spec.ts
T
s.yahyaee 7d1a50db7b fix: harden claim review and inquiry workflows
Preserve damage history and current vehicle price, restore depreciation mapping, normalize inquiry/report output, and support resumable expert review with paginated case retrieval.
2026-09-18 16:04:33 +03:30

166 lines
4.5 KiB
TypeScript

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";
describe("getExpertReplyPricingValidationError", () => {
it("rejects a blank pricing line", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
price: "",
salary: "",
totalPayment: "",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toMatch(/requires valid salary and totalPayment/);
});
it("accepts a fully priced line with a zero-valued split", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
price: "0",
salary: "10000",
totalPayment: "10000",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toBeNull();
});
it("accepts a repair line without daghi", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
price: "10000",
salary: "0",
totalPayment: "10000",
},
]),
).toBeNull();
});
it("accepts a repair line without a price", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
salary: "0",
totalPayment: "0",
},
]),
).toBeNull();
});
it("rejects recycled-value daghi without its price", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Change,
price: "0",
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.RECYCLED_PARTS_VALUE },
},
]),
).toMatch(/requires a valid daghi price/);
});
it("rejects a replacement line without a part price", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Change,
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toMatch(/price is also required/);
});
it("rejects an invalid price when a replacement line supplies one", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Change,
price: "not-a-number",
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).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();
});
it.each([
["price", "99,999", "parts[0].price"],
["salary", "100,000,000,001", "parts[0].salary"],
["totalPayment", "99,999", "parts[0].totalPayment"],
["daghi.price", "100,000,000,001", "parts[0].daghi.price"],
])(
"enforces the amount range for %s",
(field, invalidValue, expectedField) => {
const part = {
partId: 201,
typeOfDamage: TypeOfDamage.Change,
price: "1000000",
salary: "1000000",
totalPayment: "1000000",
daghi: {
option: DaghiOption.RECYCLED_PARTS_VALUE,
price: "1000000",
},
};
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,
});
},
);
});