feat(14-06): convert route tests + MCP tests to async PGlite
- All 8 route test files: async createTestApp(), async beforeEach - MCP tools test: await createTestDb(), await getCollectionSummary() - Fixed MCP tool files: added await to all service calls in items, categories, threads, setups tools - Fixed MCP collection resource: made getCollectionSummary async - Fixed MCP index.ts: await getCollectionSummary call - Increased test timeout to 30s in bunfig.toml for PGlite WASM overhead - Zero SQLite references remain in tests/ Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,8 @@ import { Hono } from "hono";
|
||||
import { authRoutes } from "../../src/server/routes/auth.ts";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono<{ Variables: { db?: any } }>();
|
||||
|
||||
app.use("*", async (c, next) => {
|
||||
@@ -19,8 +19,8 @@ function createTestApp() {
|
||||
describe("Auth Routes", () => {
|
||||
let app: Hono;
|
||||
|
||||
beforeEach(() => {
|
||||
const testApp = createTestApp();
|
||||
beforeEach(async () => {
|
||||
const testApp = await createTestApp();
|
||||
app = testApp.app;
|
||||
});
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import { categoryRoutes } from "../../src/server/routes/categories.ts";
|
||||
import { itemRoutes } from "../../src/server/routes/items.ts";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono();
|
||||
|
||||
// Inject test DB into context for all routes
|
||||
@@ -22,8 +22,8 @@ function createTestApp() {
|
||||
describe("Category Routes", () => {
|
||||
let app: Hono;
|
||||
|
||||
beforeEach(() => {
|
||||
const testApp = createTestApp();
|
||||
beforeEach(async () => {
|
||||
const testApp = await createTestApp();
|
||||
app = testApp.app;
|
||||
});
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import { categoryRoutes } from "../../src/server/routes/categories.ts";
|
||||
import { itemRoutes } from "../../src/server/routes/items.ts";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono();
|
||||
|
||||
// Inject test DB into context for all routes
|
||||
@@ -22,8 +22,8 @@ function createTestApp() {
|
||||
describe("Item Routes", () => {
|
||||
let app: Hono;
|
||||
|
||||
beforeEach(() => {
|
||||
const testApp = createTestApp();
|
||||
beforeEach(async () => {
|
||||
const testApp = await createTestApp();
|
||||
app = testApp.app;
|
||||
});
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import { oauthRoutes, wellKnownRoute } from "../../src/server/routes/oauth.ts";
|
||||
import { createUser } from "../../src/server/services/auth.service.ts";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono<{ Variables: { db?: any } }>();
|
||||
app.use("*", async (c, next) => {
|
||||
c.set("db", db);
|
||||
@@ -18,8 +18,8 @@ function createTestApp() {
|
||||
return { app, db };
|
||||
}
|
||||
|
||||
function createFullTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createFullTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono<{ Variables: { db?: any } }>();
|
||||
app.use("*", async (c, next) => {
|
||||
c.set("db", db);
|
||||
@@ -39,10 +39,10 @@ function generatePkce() {
|
||||
|
||||
describe("OAuth Routes", () => {
|
||||
let app: Hono;
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
let db: any;
|
||||
|
||||
beforeEach(async () => {
|
||||
const testApp = createTestApp();
|
||||
const testApp = await createTestApp();
|
||||
app = testApp.app;
|
||||
db = testApp.db;
|
||||
await createUser(db, "admin", "secret123");
|
||||
@@ -182,7 +182,7 @@ describe("OAuth Routes", () => {
|
||||
});
|
||||
|
||||
describe("Full OAuth flow", () => {
|
||||
it("register → authorize → token exchange", async () => {
|
||||
it("register -> authorize -> token exchange", async () => {
|
||||
// 1. Register client
|
||||
const regRes = await app.request("/oauth/register", {
|
||||
method: "POST",
|
||||
@@ -245,9 +245,9 @@ describe("OAuth Routes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Full OAuth → MCP Flow", () => {
|
||||
it("complete flow: register → authorize → token → MCP call", async () => {
|
||||
const { app, db } = createFullTestApp();
|
||||
describe("Full OAuth -> MCP Flow", () => {
|
||||
it("complete flow: register -> authorize -> token -> MCP call", async () => {
|
||||
const { app, db } = await createFullTestApp();
|
||||
await createUser(db, "admin", "secret123");
|
||||
const { verifier, challenge } = generatePkce();
|
||||
|
||||
@@ -321,7 +321,7 @@ describe("OAuth Routes", () => {
|
||||
});
|
||||
|
||||
it("rejects MCP call without auth when user exists", async () => {
|
||||
const { app, db } = createFullTestApp();
|
||||
const { app, db } = await createFullTestApp();
|
||||
await createUser(db, "admin", "secret123");
|
||||
|
||||
const mcpRes = await app.request("/mcp", {
|
||||
|
||||
@@ -6,8 +6,8 @@ import { setupRoutes } from "../../src/server/routes/setups";
|
||||
import { threadRoutes } from "../../src/server/routes/threads";
|
||||
import { createTestDb } from "../helpers/db";
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono();
|
||||
app.use("*", async (c, next) => {
|
||||
c.set("db", db);
|
||||
@@ -23,8 +23,8 @@ function createTestApp() {
|
||||
describe("Invalid ID parameter handling", () => {
|
||||
let app: Hono;
|
||||
|
||||
beforeEach(() => {
|
||||
app = createTestApp();
|
||||
beforeEach(async () => {
|
||||
app = await createTestApp();
|
||||
});
|
||||
|
||||
describe("items", () => {
|
||||
|
||||
@@ -4,8 +4,8 @@ import { itemRoutes } from "../../src/server/routes/items.ts";
|
||||
import { setupRoutes } from "../../src/server/routes/setups.ts";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono();
|
||||
|
||||
app.use("*", async (c, next) => {
|
||||
@@ -39,8 +39,8 @@ async function createItemViaAPI(app: Hono, data: any) {
|
||||
describe("Setup Routes", () => {
|
||||
let app: Hono;
|
||||
|
||||
beforeEach(() => {
|
||||
const testApp = createTestApp();
|
||||
beforeEach(async () => {
|
||||
const testApp = await createTestApp();
|
||||
app = testApp.app;
|
||||
});
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import { Hono } from "hono";
|
||||
import { threadRoutes } from "../../src/server/routes/threads.ts";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono();
|
||||
|
||||
// Inject test DB into context for all routes
|
||||
@@ -38,8 +38,8 @@ async function createCandidateViaAPI(app: Hono, threadId: number, data: any) {
|
||||
describe("Thread Routes", () => {
|
||||
let app: Hono;
|
||||
|
||||
beforeEach(() => {
|
||||
const testApp = createTestApp();
|
||||
beforeEach(async () => {
|
||||
const testApp = await createTestApp();
|
||||
app = testApp.app;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user