codex-lv4-may-2025

Level Navigation: 1 2 3 (4ℹ️) (5ℹ️) 6 7 8 9 10 11 12 13 14⚡ 15⚡ (16ℹ️) 17 18 19 20 21 22 23 24 25 26⚡ 27⚡ 28⚡ 29 30 31 32 33 34 35 36 37 38 39⚡ 40⚡

Level 35: Test a POST Route

Add a test for your POST route that creates a new record. Test that it returns status 201, includes the created record, and generates an ID.

Show Me: POST route test

it('creates a new item', async () => {
  const response = await request(app)
    .post('/items')
    .send({ title: 'Test Notebook', price: 6.99 });
  expect(response.status).toBe(201);
  expect(response.body).toMatchObject({ title: 'Test Notebook', price: 6.99 });
  expect(response.body.id).toBeDefined();
});