all the haul

This commit is contained in:
2026-04-07 23:56:31 +00:00
parent 87cce83030
commit 24f303355b
244 changed files with 33743 additions and 11249 deletions
+101 -13
View File
@@ -6,7 +6,7 @@ import { buildMockCatalogItem, buildMockConstants } from "../setup";
// ---------------------------------------------------------------------------
function createStablePrismaMock(
overrides: Record<string, Record<string, any>> = {},
overrides: Record<string, Record<string, any>> = {}
) {
return new Proxy(
{},
@@ -17,7 +17,7 @@ function createStablePrismaMock(
if (overrides[model]) return overrides[model];
return new Proxy({}, { get: () => mock(() => Promise.resolve(null)) });
},
},
}
);
}
@@ -43,7 +43,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(mockData)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -60,7 +60,7 @@ describe("procurement manager", () => {
prisma: createStablePrismaMock({
catalogItem: { findFirst },
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -77,7 +77,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -108,7 +108,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -126,7 +126,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -134,6 +134,48 @@ describe("procurement manager", () => {
const opts = findMany.mock.calls[0]?.[0];
expect(opts.skip).toBe(0); // (max(0,1)-1) * 10 = 0
});
test("falls back to safe pagination when page/rpp are invalid", async () => {
const findMany = mock(() => Promise.resolve([]));
mock.module("../../src/constants", () =>
buildMockConstants({
prisma: createStablePrismaMock({
catalogItem: {
findMany,
findFirst: mock(() => Promise.resolve(null)),
},
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
await procurement.fetchPages(Number.NaN, Number.NaN);
const opts = findMany.mock.calls[0]?.[0];
expect(opts.skip).toBe(0);
expect(opts.take).toBe(30);
});
test("uses relational manufacturer filter when manufacturer option is provided", async () => {
const findMany = mock(() => Promise.resolve([]));
mock.module("../../src/constants", () =>
buildMockConstants({
prisma: createStablePrismaMock({
catalogItem: {
findMany,
findFirst: mock(() => Promise.resolve(null)),
},
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
await procurement.fetchPages(1, 20, { manufacturer: "Ubiquiti" });
const where = findMany.mock.calls[0]?.[0]?.where;
expect(JSON.stringify(where)).toContain(
'"manufacturer":{"is":{"name":{"contains":"Ubiquiti"'
);
});
});
// -------------------------------------------------------------------
@@ -150,13 +192,59 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
const result = await procurement.search("switch", 1, 10);
expect(result).toBeArrayOfSize(1);
});
test("ignores invalid numeric filters instead of passing NaN to Prisma", async () => {
const findMany = mock(() => Promise.resolve([]));
mock.module("../../src/constants", () =>
buildMockConstants({
prisma: createStablePrismaMock({
catalogItem: {
findMany,
findFirst: mock(() => Promise.resolve(null)),
},
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
await procurement.search("switch", Number.NaN, Number.NaN, {
minPrice: Number.NaN,
maxPrice: Number.NaN,
});
const where = findMany.mock.calls[0]?.[0]?.where;
expect(where).toHaveProperty("OR");
expect(JSON.stringify(where)).not.toContain("NaN");
});
test("uses relational manufacturer search clause", async () => {
const findMany = mock(() => Promise.resolve([]));
mock.module("../../src/constants", () =>
buildMockConstants({
prisma: createStablePrismaMock({
catalogItem: {
findMany,
findFirst: mock(() => Promise.resolve(null)),
},
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
await procurement.search("wir", 1, 20);
const where = findMany.mock.calls[0]?.[0]?.where;
expect(JSON.stringify(where)).toContain(
'"manufacturer":{"is":{"name":{"contains":"wir"'
);
});
});
// -------------------------------------------------------------------
@@ -172,7 +260,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -194,7 +282,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -217,7 +305,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -235,7 +323,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");
@@ -256,7 +344,7 @@ describe("procurement manager", () => {
findFirst: mock(() => Promise.resolve(null)),
},
}),
}),
})
);
const { procurement } = await import("../../src/managers/procurement");