// Test helper: start a throwaway Express app on an ephemeral port and return its // base URL + a close(). Uses the built-in fetch (Node 18+) so tests need no // extra HTTP dependency. Tests here exercise middleware in isolation and do NOT // touch the database. const express = require('express') async function startApp(configure) { const app = express() app.use(express.json()) configure(app) const server = await new Promise((resolve) => { const s = app.listen(0, '127.0.0.1', () => resolve(s)) }) const { port } = server.address() return { url: `http://127.0.0.1:${port}`, close: () => new Promise((resolve) => server.close(resolve)), } } module.exports = { startApp }