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
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.
Add tests to the existing __tests__/orders.test.ts file that cover:
Produce:
__tests__/orders.test.ts with the new tests addedThe API endpoints:
PATCH /api/orders/:id/status — body: { status: string }, valid values: 'received', 'preparing', 'ready', 'cancelled'GET /api/orders?status=<value> — returns filtered order listThe 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(); }); });