fix(16): add async/await to createTestDb in route and MCP tests

Route and MCP test files were calling createTestDb() without await,
causing db to be a Promise object instead of a Drizzle instance.
Also rewrote auth route tests for OIDC-based auth (merge picked old version).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-05 11:52:38 +02:00
parent c4a7a6c76f
commit 5ae3836d64
8 changed files with 139 additions and 130 deletions

View File

@@ -14,7 +14,7 @@ function parseResult(result: {
describe("MCP Item Tools", () => {
test("list_items returns array", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerItemTools(db, userId);
const result = await tools.list_items({});
const data = parseResult(result);
@@ -22,7 +22,7 @@ describe("MCP Item Tools", () => {
});
test("create_item creates and returns item", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerItemTools(db, userId);
const result = await tools.create_item({
name: "Test Tent",
@@ -38,7 +38,7 @@ describe("MCP Item Tools", () => {
});
test("get_item retrieves by ID", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerItemTools(db, userId);
const created = parseResult(
await tools.create_item({ name: "Sleeping Bag", categoryId: 1 }),
@@ -50,7 +50,7 @@ describe("MCP Item Tools", () => {
});
test("get_item returns error for missing item", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerItemTools(db, userId);
const result = await tools.get_item({ id: 999 });
const data = parseResult(result);
@@ -58,7 +58,7 @@ describe("MCP Item Tools", () => {
});
test("delete_item removes item", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerItemTools(db, userId);
const created = parseResult(
await tools.create_item({ name: "To Delete", categoryId: 1 }),
@@ -76,7 +76,7 @@ describe("MCP Item Tools", () => {
describe("MCP Category Tools", () => {
test("list_categories returns array with Uncategorized", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerCategoryTools(db, userId);
const result = await tools.list_categories();
const data = parseResult(result);
@@ -86,7 +86,7 @@ describe("MCP Category Tools", () => {
});
test("create_category creates a new category", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerCategoryTools(db, userId);
const result = await tools.create_category({
name: "Shelter",
@@ -100,7 +100,7 @@ describe("MCP Category Tools", () => {
describe("MCP Thread Tools", () => {
test("create_thread starts a thread with status active", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerThreadTools(db, userId);
const result = await tools.create_thread({
name: "Handlebar Bag",
@@ -112,7 +112,7 @@ describe("MCP Thread Tools", () => {
});
test("add_candidate adds to thread", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerThreadTools(db, userId);
const thread = parseResult(
await tools.create_thread({ name: "Saddle Bag", categoryId: 1 }),
@@ -132,7 +132,7 @@ describe("MCP Thread Tools", () => {
});
test("resolve_thread picks winner and creates item", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const threadTools = registerThreadTools(db, userId);
const itemTools = registerItemTools(db, userId);
@@ -179,7 +179,7 @@ describe("MCP Thread Tools", () => {
describe("MCP Setup Tools", () => {
test("create_setup and list_setups", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const tools = registerSetupTools(db, userId);
await tools.create_setup({ name: "Weekend Trip" });
const result = await tools.list_setups();
@@ -189,7 +189,7 @@ describe("MCP Setup Tools", () => {
});
test("get_setup returns setup with items", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const setupTools = registerSetupTools(db, userId);
const itemTools = registerItemTools(db, userId);
@@ -210,8 +210,8 @@ describe("MCP Setup Tools", () => {
});
describe("MCP Collection Summary Resource", () => {
test("returns overview with correct counts", () => {
const { db, userId } = createTestDb();
test("returns overview with correct counts", async () => {
const { db, userId } = await createTestDb();
const summary = getCollectionSummary(db, userId);
expect(summary.overview).toBeDefined();
@@ -223,7 +223,7 @@ describe("MCP Collection Summary Resource", () => {
});
test("reflects items and threads after creation", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const itemTools = registerItemTools(db, userId);
const threadTools = registerThreadTools(db, userId);
@@ -254,7 +254,7 @@ describe("MCP Collection Summary Resource", () => {
describe("MCP Cross-User Isolation", () => {
test("user 2 cannot see user 1's items via MCP tools", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const userId2 = createSecondTestUser(db);
const user1Tools = registerItemTools(db, userId);
@@ -285,7 +285,7 @@ describe("MCP Cross-User Isolation", () => {
});
test("user 2 cannot access user 1's item by ID", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const userId2 = createSecondTestUser(db);
const user1Tools = registerItemTools(db, userId);
@@ -305,7 +305,7 @@ describe("MCP Cross-User Isolation", () => {
});
test("user 2 cannot see user 1's threads via MCP tools", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const userId2 = createSecondTestUser(db);
const user1Tools = registerThreadTools(db, userId);
@@ -329,7 +329,7 @@ describe("MCP Cross-User Isolation", () => {
});
test("collection summary is scoped to user", async () => {
const { db, userId } = createTestDb();
const { db, userId } = await createTestDb();
const userId2 = createSecondTestUser(db);
const user1Tools = registerItemTools(db, userId);