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

Expand Test Coverage for Order Status and Filtering

Problem/Feature Description

An Express API for a food ordering system has basic tests for creating and retrieving orders, but two important features have never been tested: status updates and order filtering. The status update endpoint (PATCH /api/orders/:id/status) was recently modified to support a new 'cancelled' status, and no one is sure if the validation logic still works correctly. The filtering endpoint (GET /api/orders?status=...) is used heavily by the front-end dashboard, but a bug was reported last week where filtering by 'preparing' also returned orders in 'received' status.

A senior engineer has asked you to add tests for these two areas before the next release. The tests should be added to the existing test file alongside the tests that are already there.

Output Specification

Add tests to the existing __tests__/orders.test.ts file that cover:

  • PATCH status update: successful update with a valid status
  • PATCH status update: rejection of an invalid status value
  • GET with query parameter: filtering orders by status returns only matching results

Produce:

  • An updated __tests__/orders.test.ts with the new tests added
  • A brief comment or block at the top of each new test describing what it covers

The API endpoints:

  • PATCH /api/orders/:id/status — body: { status: string }, valid values: 'received', 'preparing', 'ready', 'cancelled'
  • GET /api/orders?status=<value> — returns filtered order list

Input Files

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

=============== FILE: tests/orders.test.ts =============== import { describe, it, expect, beforeEach } from 'vitest'; import request from 'supertest'; import { app } from '../src/server'; import { resetDatabase } from '../src/db';

describe('Orders API', () => { beforeEach(() => { resetDatabase(); });

it('GET /api/orders returns order list', async () => { const res = await request(app).get('/api/orders'); expect(res.status).toBe(200); expect(Array.isArray(res.body.data)).toBe(true); });

it('POST /api/orders rejects empty body', async () => { const res = await request(app).post('/api/orders').send({}); expect(res.status).toBe(400); expect(res.body.error).toBeDefined(); });

it('POST /api/orders creates an order', async () => { const res = await request(app) .post('/api/orders') .send({ customer_name: 'Alice', items: [{ menu_item_id: 1, quantity: 1 }] }); expect(res.status).toBe(201); expect(res.body.data.id).toBeDefined(); }); });

evals

scenario-1

criteria.json

task.md

tile.json