fix(pl24): correct p5fiat vinfoBasic label/value extraction

The Fiat vinfoBasic record carries the row under `values` like p5vwag, but the
inner field names are swapped: p5fiat uses values.key=<label>,
values.description=<value> (vwag uses values.description=<label>,
values.value=<value>). The first pass read values.description as the label, so
model fell back to the numeric description code ("319") and year to 0. Detect
the shape via values.key. Live-verified: ZFA Panda→"Panda POP 1.2 8V 69CV 5M E6"
/2014, Grande Punto/2009, 500L/2015. Spec fixture corrected to the real shape.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-04 17:12:22 +03:00
parent e2a85ff94f
commit 9809012be5
2 changed files with 35 additions and 25 deletions

View File

@@ -42,12 +42,34 @@ describe("PL24Service.parseVehicleResponse — p5fiat shape", () => {
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" },
{
description: "ZFA31200003376360",
values: { key: "Sasi numarasi", description: "ZFA31200003376360" },
},
{
description: "319118001000 (33)",
values: { key: "Model", description: "319118001000 (33)" },
},
{
description: "Panda POP 1.2 8V 69CV 5M E6",
values: { key: "Model bilgisi", description: "Panda POP 1.2 8V 69CV 5M E6" },
},
{
description: "05/09/2014",
values: { key: "Üretim tarihi", description: "05/09/2014" },
},
{
description: "MODEL YILI = 2014 YILI",
values: { key: "MY", code: "NO", description: "MODEL YILI = 2014 YILI" },
},
{
description: "GEARBOX DESIGN = MECHANIC TRANSMISSION",
values: {
key: "PC",
code: "C514",
description: "GEARBOX DESIGN = MECHANIC TRANSMISSION",
},
},
],
},
},

View File

@@ -999,31 +999,19 @@ export class PL24Service {
const segments =
(data.segments as Record<
string,
{
records?: Array<{
values?: Record<string, string>;
key?: string;
description?: string;
code?: string;
}>;
}
{ records?: Array<{ values?: Record<string, string | undefined> }> }
>) || {};
const vinfoRecords = segments.vinfoBasic?.records || [];
const vehicleData: Record<string, string> = {};
for (const record of vinfoRecords) {
// Two record shapes across P5 backends:
// p5vwag etc.: { values: { description: <label>, value: <value> } }
const v = record.values;
if (!v) continue;
// Both shapes carry the row under `values`, but the inner field names differ:
// p5vwag etc.: { description: <label>, value: <value> }
// p5fiat: { key: <label>, description: <value>, code?: <code> }
let label = "";
let value = "";
if (record.values) {
label = record.values.description || "";
value = record.values.value || "";
} else if (record.key) {
label = record.key;
value = record.description || "";
}
const label = (v.key !== undefined ? v.key : v.description) || "";
const value = (v.key !== undefined ? v.description : v.value) || "";
if (!label) continue;
const key = label.toLowerCase().replace(/[\s\/]+/g, "_");
if (!(key in vehicleData)) vehicleData[key] = value.replace(/\r?\n/g, " ").trim();