test(pl24): cover p5fiat vinfoBasic parse shape + p5vwag regression

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-04 17:02:30 +03:00
parent 4a115db885
commit e2a85ff94f

View File

@@ -0,0 +1,95 @@
import { describe, expect, it } from "vitest";
import { PL24Service } from "./pl24.service";
// configService.get(key, default) → default; everything else unused by parseVehicleResponse.
const configStub = { get: (_k: string, d?: unknown) => d } as never;
const svc = new PL24Service(
{} as never, // authService
{} as never, // fordLegacyService
{} as never, // psaService
{} as never, // volvoService
{} as never, // fordService
{} as never, // opelService
{} as never, // hyundaiKiaService
configStub, // configService
{} as never, // redis
{} as never, // storage
);
const p = svc as unknown as {
parseVehicleResponse(
vin: string,
data: Record<string, unknown>,
serviceName: string,
): {
brand: string;
model: string;
year: number;
productionDate: string | null;
catalogInfo?: { mainGroupsPath?: string };
};
};
describe("PL24Service.parseVehicleResponse — p5fiat shape", () => {
// Real /p5fiat directAccess shape (captured live 2026-06-04, de-708171):
// vinfoBasic records are {key,description,code?}, NOT {values:{description,value}}.
const fiatData = {
resultStatus: "VEHICLE_IDENTIFIED",
description: "319",
link: {
wid: "mainGroupsTable",
path: "/p5fiat/extern/groups/vin/maingroups?allMarkets=true&lang=tr&modelCode=33&serviceName=fiatp_parts&vin=ZFA31200003376360",
},
segments: {
vinfoBasic: {
records: [
{ key: "Sasi numarasi", description: "ZFA31200003376360" },
{ key: "Model", description: "319118001000 (33)" },
{ key: "Model bilgisi", description: "Panda POP 1.2 8V 69CV 5M E6" },
{ key: "Üretim tarihi", description: "05/09/2014" },
{ key: "MY", code: "NO", description: "MODEL YILI = 2014 YILI" },
{ key: "PC", code: "C514", description: "GEARBOX DESIGN = MECHANIC TRANSMISSION" },
],
},
},
};
it("reads the friendly model from 'Model bilgisi' (not the numeric 'Model' code)", () => {
const r = p.parseVehicleResponse("ZFA31200003376360", fiatData, "fiatp_parts");
expect(r.brand).toBe("Fiat");
expect(r.model).toBe("Panda POP 1.2 8V 69CV 5M E6");
});
it("derives year + production date when there is no plain model_yili field", () => {
const r = p.parseVehicleResponse("ZFA31200003376360", fiatData, "fiatp_parts");
expect(r.year).toBe(2014);
expect(r.productionDate).toBe("05/09/2014");
});
it("uses link.path as the main-groups path", () => {
const r = p.parseVehicleResponse("ZFA31200003376360", fiatData, "fiatp_parts");
expect(r.catalogInfo?.mainGroupsPath).toContain("/p5fiat/extern/groups/vin/maingroups");
});
});
describe("PL24Service.parseVehicleResponse — p5vwag shape still works (regression)", () => {
const vwagData = {
resultStatus: "VEHICLE_IDENTIFIED",
description: "Golf - 1.6 TDI",
link: { path: "/p5vwag/extern/groups/vin/maingroups?vin=WVWZZZ" },
segments: {
vinfoBasic: {
records: [
{ values: { description: "Model", value: "Golf" } },
{ values: { description: "Model yili", value: "2018" } },
],
},
},
};
it("reads model/year from the {values:{description,value}} shape", () => {
const r = p.parseVehicleResponse("WVWZZZ1KZAW000000", vwagData as never, "vw_parts");
expect(r.model).toBe("Golf");
expect(r.year).toBe(2018);
expect(r.catalogInfo?.mainGroupsPath).toContain("/p5vwag/");
});
});