fix: update all tests and MCP catalog tool for manufacturerId schema migration
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, it } from "bun:test";
|
||||
import { Hono } from "hono";
|
||||
import { globalItems, setups } from "../../src/db/schema.ts";
|
||||
import { globalItems, manufacturers, setups } from "../../src/db/schema.ts";
|
||||
import { discoveryRoutes } from "../../src/server/routes/discovery.ts";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
@@ -20,17 +20,28 @@ async function createTestApp() {
|
||||
return { app, db, userId };
|
||||
}
|
||||
|
||||
async function insertManufacturer(db: TestDb["db"], name: string) {
|
||||
const slug = name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
|
||||
const [row] = await db
|
||||
.insert(manufacturers)
|
||||
.values({ name, slug, website: `https://${slug}.com` })
|
||||
.onConflictDoUpdate({ target: manufacturers.slug, set: { name } })
|
||||
.returning();
|
||||
return row!;
|
||||
}
|
||||
|
||||
async function insertGlobalItem(
|
||||
db: TestDb["db"],
|
||||
brand: string,
|
||||
model: string,
|
||||
category?: string,
|
||||
) {
|
||||
const m = await insertManufacturer(db, brand);
|
||||
const [row] = await db
|
||||
.insert(globalItems)
|
||||
.values({ brand, model, category: category ?? "bags" })
|
||||
.values({ manufacturerId: m.id, model, category: category ?? "bags" })
|
||||
.returning();
|
||||
return row;
|
||||
return row!;
|
||||
}
|
||||
|
||||
async function insertPublicSetup(
|
||||
@@ -142,14 +153,16 @@ describe("Discovery Routes", () => {
|
||||
const olderTime = new Date("2024-01-01T00:00:00Z");
|
||||
const newerTime = new Date("2024-06-01T00:00:00Z");
|
||||
|
||||
const mA = await insertManufacturer(db, "Brand A");
|
||||
const mB = await insertManufacturer(db, "Brand B");
|
||||
await db.insert(globalItems).values({
|
||||
brand: "Brand A",
|
||||
manufacturerId: mA.id,
|
||||
model: "Model A",
|
||||
category: "bags",
|
||||
createdAt: olderTime,
|
||||
});
|
||||
await db.insert(globalItems).values({
|
||||
brand: "Brand B",
|
||||
manufacturerId: mB.id,
|
||||
model: "Model B",
|
||||
category: "bags",
|
||||
createdAt: newerTime,
|
||||
|
||||
Reference in New Issue
Block a user