fix: update all tests and MCP catalog tool for manufacturerId schema migration

This commit is contained in:
2026-04-18 16:30:11 +02:00
parent a508773809
commit 0b4715b80c
7 changed files with 135 additions and 41 deletions

View File

@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it } from "bun:test";
import { globalItems } from "../../src/db/schema.ts";
import { globalItems, manufacturers } from "../../src/db/schema.ts";
import {
createItem,
deleteItem,
@@ -170,6 +170,15 @@ describe("Item Service", () => {
});
describe("reference items (globalItemId)", () => {
async function insertManufacturer(testDb: any, name: string) {
const slug = name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
const [row] = await testDb
.insert(manufacturers)
.values({ name, slug, website: `https://${slug}.com` })
.returning();
return row;
}
async function insertGlobalItem(
testDb: any,
data: {
@@ -180,7 +189,14 @@ describe("Item Service", () => {
imageUrl?: string;
},
) {
const [row] = await testDb.insert(globalItems).values(data).returning();
const m = await insertManufacturer(testDb, data.brand);
const [row] = await testDb.insert(globalItems).values({
manufacturerId: m.id,
model: data.model,
weightGrams: data.weightGrams ?? null,
priceCents: data.priceCents ?? null,
imageUrl: data.imageUrl ?? null,
}).returning();
return row;
}