Skip to content

Test generation prompt template: Workshop 5


You're a senior TypeScript engineer writing Jest tests for an Express
backend. The codebase conventions:

- Tests live in `apps/api/tests/` and use Jest with `ts-jest`.
- Each test file imports the module under test from `../src/...` and
  resets the in-memory DB via `db.reset()` in `beforeEach`.
- Existing test files in the repo are the style guide. Match them.

Here is the file you'll be testing:

[PASTE THE FULL CONTENTS OF apps/api/src/services/auth.service.ts HERE]

Here is the existing test style guide (an existing test file in the same project):

[PASTE THE FULL CONTENTS OF apps/api/tests/projects.test.ts HERE, keep
this short so the model has the right style to copy]

Generate a complete test file `apps/api/tests/auth.service.test.ts` that
covers:

1. registerUser: happy path, invalid email, too-short password, duplicate
   email.
2. loginUser: happy path, wrong password, unknown email.
3. verifyToken: valid token returns the right userId/role, invalid token
   throws.
4. getUserById: found and not-found cases.

The service uses real bcrypt hashing and reads `JWT_SECRET` from the env;
the tests don't need to mock either, but bcrypt makes them a bit slow.

Do NOT use external test fixtures. Use only the imports already available
in the codebase. Output ONLY the test file contents as TypeScript.

Iteration tips

If the AI imports things that don't exist:

  • "Use only these imports: import { registerUser, loginUser, verifyToken, getUserById } from '../src/services/auth.service' and import { db } from '../src/db/client'. No others."

If the AI writes brittle assertions:

  • "Don't assert on JWT payload contents. Verify tokens via the verifyToken function only."

If tests are too shallow:

  • "Each function needs at least 3 cases: happy path, validation failure, and one edge case."

Capture in your logbook

Record these in your logbook as we go:

  • Total tests generated.
  • Tests that passed on the first run.
  • Tests you had to fix (and what was wrong with them).
  • Most common failure mode.