test(catalog): cover P4 VIN group-node gate (children + loadError)
Mirrors the PSA VIN-scope tests for the new …group.action parent gate: a Ford json-vin-sub-group.action node with a positional link_wid routes to children (not a silent empty leaf), and an empty drill surfaces loadError. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -320,6 +320,84 @@ describe("CategoriesService", () => {
|
||||
"drill-load-error",
|
||||
);
|
||||
});
|
||||
|
||||
it("routes a P4 Ford VIN node (json-vin-sub-group.action, positional link_wid) to children, not an empty leaf", async () => {
|
||||
// link_wid "1" is a positional code (not a *Group* table) so the link_wid
|
||||
// group-drill branch misses it; the path is …group.action (not /psa/, not
|
||||
// vin-group.action) so the PSA / Volvo branches miss it too. Before the
|
||||
// dedicated gate these fell through to the leaf parts path → silent empty
|
||||
// panel (Ford/Nissan/Opel analog of the PSA-parent-gate gap).
|
||||
const category = {
|
||||
id: "ford1",
|
||||
name: "elektrik sistemi",
|
||||
nameOriginal: "elektrik sistemi",
|
||||
parentId: null,
|
||||
vehicleId: "v1",
|
||||
source: "pl24",
|
||||
linkPath: "/ford/fordp_parts/json-vin-sub-group.action?mainGroupId=CAP1&vin=WF0FXX",
|
||||
linkWid: "1",
|
||||
hasSubgroups: null,
|
||||
hasParts: null,
|
||||
};
|
||||
let selectCall = 0;
|
||||
const db = {
|
||||
select: vi.fn().mockImplementation(() => {
|
||||
selectCall++;
|
||||
const captured = selectCall;
|
||||
const c: Record<string, any> = {};
|
||||
c.from = vi.fn().mockReturnValue(c);
|
||||
c.where = vi.fn().mockImplementation(() => (captured === 2 ? [] : c));
|
||||
c.limit = vi.fn().mockReturnValue([category]);
|
||||
return c;
|
||||
}),
|
||||
execute: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
const { service } = createService(db);
|
||||
const discovered = [{ id: "sg1", name: "kablolar", children: undefined }];
|
||||
vi.spyOn(service, "getChildren").mockResolvedValue(discovered as any);
|
||||
|
||||
const result = await service.getCategoryWithParts("ford1");
|
||||
|
||||
expect(service.getChildren).toHaveBeenCalledWith("ford1");
|
||||
expect(result.parts).toEqual([]);
|
||||
expect((result as { children?: unknown }).children).toEqual(discovered);
|
||||
});
|
||||
|
||||
it("surfaces loadError when a P4 group.action drill comes back empty (not a silent leaf)", async () => {
|
||||
const category = {
|
||||
id: "ford2",
|
||||
name: "kaporta",
|
||||
nameOriginal: "kaporta",
|
||||
parentId: null,
|
||||
vehicleId: "v1",
|
||||
source: "pl24",
|
||||
linkPath: "/ford/fordp_parts/json-vin-sub-group.action?mainGroupId=GDB&vin=WF0FXX",
|
||||
linkWid: "2",
|
||||
hasSubgroups: null,
|
||||
hasParts: null,
|
||||
};
|
||||
let selectCall = 0;
|
||||
const db = {
|
||||
select: vi.fn().mockImplementation(() => {
|
||||
selectCall++;
|
||||
const captured = selectCall;
|
||||
const c: Record<string, any> = {};
|
||||
c.from = vi.fn().mockReturnValue(c);
|
||||
c.where = vi.fn().mockImplementation(() => (captured === 2 ? [] : c));
|
||||
c.limit = vi.fn().mockReturnValue([category]);
|
||||
return c;
|
||||
}),
|
||||
execute: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
const { service } = createService(db);
|
||||
vi.spyOn(service, "getChildren").mockResolvedValue([] as any);
|
||||
|
||||
const result = await service.getCategoryWithParts("ford2");
|
||||
|
||||
expect(service.getChildren).toHaveBeenCalledWith("ford2");
|
||||
expect((result as { loadError?: boolean }).loadError).toBe(true);
|
||||
expect((result as { children?: unknown }).children).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAncestors", () => {
|
||||
|
||||
Reference in New Issue
Block a user