CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/api-testing-first-steps

Get test coverage on an Express/Node API fast — the first 5 tests that catch

94

1.26x
Quality

90%

Does it follow best practices?

Impact

100%

1.26x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-3/

Add First Tests to an Inherited Express API

Problem/Feature Description

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.

Output Specification

Produce:

  • A package.json with updated scripts and devDependencies
  • A Vitest configuration file
  • A src/server.ts that is safe to import in tests
  • A test file at __tests__/subscriptions.test.ts with your initial test suite
  • A testing-strategy.md that documents: (a) which routes you tested and why, (b) what you deliberately left out and why, (c) the test coverage approach

The subscriptions API endpoints:

  • GET /api/subscriptions — returns list of active subscriptions
  • POST /api/subscriptions — creates subscription (requires user_id integer, plan string: one of 'basic', 'pro', 'enterprise')
  • GET /api/subscriptions/:id — returns single subscription
  • DELETE /api/subscriptions/:id — cancels subscription

Errors are returned as { error: { message: "..." } }.

Input Files

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" } }

evals

tile.json