Get test coverage on an Express/Node API fast — the first 5 tests that catch
94
90%
Does it follow best practices?
Impact
100%
1.26xAverage score across 5 eval scenarios
Passed
No known issues
You've joined a small engineering team that maintains a subscription billing API built with Node, TypeScript, and Express. The codebase has been running in production for 18 months with no tests at all. During your first week, a deploy broke the /api/subscriptions endpoint and nobody noticed for 6 hours. Your manager has asked you to add a test suite this sprint — not comprehensive coverage, but enough to catch the most important regressions.
You've done a quick git log --name-only audit and found that src/routes/subscriptions.ts and src/routes/payments.ts change in nearly every PR. The payments routes deal with Stripe webhooks and plan changes, so correctness there is critical.
Your job is to set up the testing infrastructure and write an initial batch of tests. Given the size of the codebase and team velocity, the goal is focused, high-value coverage — not exhaustive testing.
Produce:
package.json with updated scripts and devDependenciessrc/server.ts that is safe to import in tests__tests__/subscriptions.test.ts with your initial test suitetesting-strategy.md that documents: (a) which routes you tested and why, (b) what you deliberately left out and why, (c) the test coverage approachThe subscriptions API endpoints:
GET /api/subscriptions — returns list of active subscriptionsPOST /api/subscriptions — creates subscription (requires user_id integer, plan string: one of 'basic', 'pro', 'enterprise')GET /api/subscriptions/:id — returns single subscriptionDELETE /api/subscriptions/:id — cancels subscriptionErrors are returned as { error: { message: "..." } }.
The following files are provided as inputs. Extract them before beginning.
=============== FILE: src/server.ts =============== import express from 'express'; import { subscriptionsRouter } from './routes/subscriptions'; import { paymentsRouter } from './routes/payments'; import { errorHandler } from './middleware/error-handler';
const app = express(); app.use(express.json()); app.use('/api/subscriptions', subscriptionsRouter); app.use('/api/payments', paymentsRouter); app.use(errorHandler);
app.listen(3000, () => console.log('Billing API running'));
=============== FILE: package.json =============== { "name": "billing-api", "version": "2.3.1", "scripts": { "start": "node dist/server.js", "build": "tsc" }, "dependencies": { "express": "^4.18.2", "better-sqlite3": "^9.4.3" }, "devDependencies": { "typescript": "^5.3.3", "@types/express": "^4.17.21" } }