forked from Yara724/api
YARA-883 + Side ID fixes
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { ClaimVehicleTypeV2 } from "src/static/outer-car-parts-catalog";
|
||||
import { buildCoefficientsFromPartSeverities } from "./claim-price-drop";
|
||||
import {
|
||||
partIdentityKey,
|
||||
catalogPartIdFromSelectedPart,
|
||||
resolveCatalogPartByPartId,
|
||||
resolvePartForExpertReply,
|
||||
resolveSelectedPartByPartId,
|
||||
sanitizeDamageSelectedPartV2,
|
||||
type DamageSelectedPartV2,
|
||||
} from "./outer-damage-parts";
|
||||
|
||||
@@ -21,17 +26,97 @@ describe("resolveSelectedPartByPartId", () => {
|
||||
},
|
||||
];
|
||||
|
||||
it("resolves by partIdentityKey", () => {
|
||||
expect(
|
||||
resolveSelectedPartByPartId(partIdentityKey(selected[0]), selected),
|
||||
).toBe(selected[0]);
|
||||
it("resolves by numeric catalog id", () => {
|
||||
expect(resolveSelectedPartByPartId(12, selected)).toBe(selected[0]);
|
||||
});
|
||||
|
||||
it("resolves by id:N catalog prefix", () => {
|
||||
it("resolves legacy id:N string input", () => {
|
||||
expect(resolveSelectedPartByPartId("id:12", selected)).toBe(selected[0]);
|
||||
});
|
||||
|
||||
it("resolves by index:N", () => {
|
||||
expect(resolveSelectedPartByPartId("index:1", selected)).toBe(selected[1]);
|
||||
});
|
||||
|
||||
it("exposes catalog id as numeric partId", () => {
|
||||
expect(catalogPartIdFromSelectedPart(selected[0])).toBe(12);
|
||||
});
|
||||
|
||||
it("resolves catalog id from outer catalog when not on claim", () => {
|
||||
const hit = resolveCatalogPartByPartId(201, ClaimVehicleTypeV2.HATCHBACK);
|
||||
expect(hit?.id).toBe(201);
|
||||
expect(hit?.side).toBe("left");
|
||||
expect(hit?.catalogKey).toBe("left_backfender");
|
||||
});
|
||||
|
||||
it("resolvePartForExpertReply uses catalog for new expert line", () => {
|
||||
const hit = resolvePartForExpertReply(
|
||||
201,
|
||||
[],
|
||||
ClaimVehicleTypeV2.HATCHBACK,
|
||||
);
|
||||
expect(hit?.id).toBe(201);
|
||||
});
|
||||
|
||||
it("sanitize fixes Persian side and re-hydrates from catalog id", () => {
|
||||
const fixed = sanitizeDamageSelectedPartV2(
|
||||
{
|
||||
id: 201,
|
||||
name: "گلگیر عقب (چپ)",
|
||||
side: "چپ",
|
||||
label_fa: "",
|
||||
catalogKey: "چپ",
|
||||
},
|
||||
ClaimVehicleTypeV2.HATCHBACK,
|
||||
);
|
||||
expect(fixed.side).toBe("left");
|
||||
expect(fixed.name).toBe("backfender");
|
||||
expect(fixed.catalogKey).toBe("left_backfender");
|
||||
expect(catalogPartIdFromSelectedPart(fixed)).toBe(201);
|
||||
});
|
||||
|
||||
it("internal parts have null catalog partId", () => {
|
||||
const row = sanitizeDamageSelectedPartV2({
|
||||
id: 99,
|
||||
name: "قاب موتور",
|
||||
side: "internal",
|
||||
label_fa: "قاب موتور",
|
||||
});
|
||||
expect(row.id).toBeNull();
|
||||
expect(catalogPartIdFromSelectedPart(row)).toBeNull();
|
||||
});
|
||||
|
||||
it("recovers outer part wrongly stored as internal with Persian label", () => {
|
||||
const fixed = sanitizeDamageSelectedPartV2(
|
||||
{
|
||||
id: null,
|
||||
name: "گلگیر عقب (چپ)",
|
||||
side: "internal",
|
||||
label_fa: "گلگیر عقب (چپ)",
|
||||
},
|
||||
ClaimVehicleTypeV2.HATCHBACK,
|
||||
);
|
||||
expect(fixed.id).toBe(201);
|
||||
expect(fixed.side).toBe("left");
|
||||
expect(fixed.name).toBe("backfender");
|
||||
expect(fixed.catalogKey).toBe("left_backfender");
|
||||
});
|
||||
|
||||
it("price drop resolves catalog id when claim row is corrupt", () => {
|
||||
const corrupt: DamageSelectedPartV2[] = [
|
||||
{
|
||||
id: null,
|
||||
name: "گلگیر عقب (چپ)",
|
||||
side: "internal",
|
||||
label_fa: "گلگیر عقب (چپ)",
|
||||
},
|
||||
];
|
||||
const { coefficients, errors } = buildCoefficientsFromPartSeverities(
|
||||
corrupt,
|
||||
[{ partId: 201, severity: "Minor" }],
|
||||
ClaimVehicleTypeV2.HATCHBACK,
|
||||
);
|
||||
expect(errors).toHaveLength(0);
|
||||
expect(coefficients).toEqual([2]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user