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-2/

Audit Error Response Consistency in a Booking API

Problem/Feature Description

A hotel booking API built with Express and TypeScript has been in production for several months. The front-end team has complained that error handling is inconsistent: some endpoints return { message: "not found" }, others return { error: "Bad request" }, and at least one returns an HTML error page when given unexpected input. This makes it very difficult to display useful error messages to users, since the client code can't rely on a predictable error shape.

The back-end team has agreed to standardize all error responses. Before they start refactoring, they want a test that documents the current behavior and will serve as a regression test once the fix is in place — verifying that all error conditions return errors in the same shape.

Output Specification

Write a test suite in __tests__/error-format.test.ts that:

  • Tests at least two different types of error conditions (e.g. validation failure and resource not found)
  • Verifies that both return the same response shape
  • Documents what the expected error shape should be

Also produce a short error-format-spec.md describing the error shape the tests enforce.

The API has these endpoints:

  • POST /api/bookings — requires guest_name (string) and check_in (ISO date string); returns 400 on invalid input
  • GET /api/bookings/:id — returns 404 when booking not found
  • DELETE /api/bookings/:id — returns 404 when booking not found

Input Files

The following files are provided as inputs. Extract them before beginning.

=============== FILE: src/server.ts =============== import express from 'express'; import { bookingsRouter } from './routes/bookings'; import { errorHandler } from './middleware/error-handler';

export const app = express(); app.use(express.json()); app.use('/api/bookings', bookingsRouter); app.use(errorHandler);

if (process.env.NODE_ENV !== 'test') { app.listen(3000); }

=============== FILE: package.json =============== { "name": "booking-api", "version": "1.0.0", "scripts": { "test": "vitest run", "test:watch": "vitest" }, "devDependencies": { "vitest": "^1.2.0", "supertest": "^6.3.4", "@types/supertest": "^6.0.2" } }

evals

tile.json