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

@@ -3,6 +3,7 @@ import { eq } from "drizzle-orm";
import {
globalItems,
items,
manufacturers,
setupItems,
setups,
users,
@@ -16,19 +17,34 @@ import { createTestDb } from "../helpers/db.ts";
type TestDb = Awaited<ReturnType<typeof createTestDb>>;
async function insertManufacturer(db: TestDb["db"], name: string) {
const slug = name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
const [existing] = await db
.select()
.from(manufacturers)
.where(eq(manufacturers.slug, slug));
if (existing) return existing;
const [row] = await db
.insert(manufacturers)
.values({ name, slug, website: `https://${slug}.com` })
.returning();
return row!;
}
async function insertGlobalItem(
db: TestDb["db"],
data: { brand: string; model: string; category?: string },
) {
const m = await insertManufacturer(db, data.brand);
const [row] = await db
.insert(globalItems)
.values({
brand: data.brand,
manufacturerId: m.id,
model: data.model,
category: data.category ?? null,
})
.returning();
return row;
return row!;
}
async function insertItem(db: TestDb["db"], userId: number, categoryId = 1) {