:::warning AUTO-GENERATED — do not edit
This page is generated from the MCP server snapshot content/backend-mcp.json.
Edit the source MCP server (not this file), then run npm run generate.
:::
Add pytest coverage per route (401 without token, happy path with a fake JWT)
When to use: A route was added or changed and needs test coverage before it is considered done.
Prerequisites
- The route exists and is auth-guarded.
- You know the expected happy-path response shape.
Steps
Step 1: Fetch the auth pattern to build a valid fake JWT the guard will accept in tests.
Tools: get_auth_pattern
Step 2: Write a test that calls the route with NO token and asserts 401.
Step 3: Write a happy-path test that calls the route WITH a fake JWT and asserts the expected status + response envelope.
Step 4: Add edge-case tests where relevant (400 on invalid payload, 403 on wrong role).
Step 5: Run the tests as part of the verify gate.
Tools: validate_backend_endpoint
Full recipe definition
The complete machine-readable recipe as returned by the MCP server:
{
"id": "add-tests",
"title": "Add pytest coverage per route (401 without token, happy path with a fake JWT)",
"when": "A route was added or changed and needs test coverage before it is considered done.",
"prerequisites": [
"The route exists and is auth-guarded.",
"You know the expected happy-path response shape."
],
"steps": [
{
"action": "Fetch the auth pattern to build a valid fake JWT the guard will accept in tests.",
"tools": [
"get_auth_pattern"
],
"note": "Tests must mint/patch a token consistent with the JWKS validation path — do not disable auth to make tests pass."
},
{
"action": "Write a test that calls the route with NO token and asserts 401.",
"files": [
"tests/test_<domain>_routes.py"
],
"note": "This proves the auth guard is actually wired."
},
{
"action": "Write a happy-path test that calls the route WITH a fake JWT and asserts the expected status + response envelope.",
"files": [
"tests/test_<domain>_routes.py"
],
"note": "Mock the DB layer (dynamix_wrapper / dbconnect) so the test does not hit a real database."
},
{
"action": "Add edge-case tests where relevant (400 on invalid payload, 403 on wrong role).",
"files": [
"tests/test_<domain>_routes.py"
]
},
{
"action": "Run the tests as part of the verify gate.",
"tools": [
"validate_backend_endpoint"
],
"note": "Follow run-verify; pytest must be green."
}
],
"filesToCreate": [
"tests/test_<domain>_routes.py"
],
"validation": [
"A no-token test asserts 401.",
"A fake-JWT happy-path test asserts the expected status and envelope.",
"DB layer is mocked; tests do not require a live database."
],
"doneCriteria": [
"Each route has at least a 401 test and a happy-path test.",
"pytest passes under run-verify."
],
"commonMistakes": [
"Disabling/short-circuiting auth to make the happy-path test pass.",
"Hitting a real database instead of mocking dynamix_wrapper/dbconnect.",
"Testing only the happy path and skipping the 401 case.",
"Asserting on a shape that differs from the actual response envelope."
],
"relatedRecipes": [
"create-endpoint",
"add-auth-guard",
"run-verify"
]
}