Write tests for one REST endpoint
Writes tests for one REST endpoint you own, covering status codes, response shape, validation and auth, after reading the code.
Task:
Write a test file in [test framework and language] for the REST endpoint whose code is in the material.
Context:
The endpoint is [method and path] in a service I own, and I run the tests against [local or test environment, never production]. Valid requests need [authentication method].
Rules:
- Read the code first and list the behaviors you found, such as status codes, required fields and permission checks, before writing tests.
- Write one test per behavior with a name that states the expected result, including at least 2 error cases and 1 permission case.
- Check the status code, the response shape and one key value, and avoid asserting values that change per run.
- Read tokens and URLs from environment variables, and never ask me to paste secrets.
- If the code leaves a behavior unclear, write a "todo" test that names the question instead of guessing.
Result:
The list of behaviors in at most 6 lines, then the complete test file with comments, then 3 lines on how to run it.
Material:
[paste the endpoint code here]