API Testing error Error: Request failed with status code 401
The API rejected the request as unauthenticated, and in test suites this is often a token lifecycle bug, not a credentials typo.
Why this happens
- The auth token expired between when it was fetched (e.g. in a `beforeAll`) and when a later test used it
- Tests run in parallel and one test's login invalidated another's session/token
- The token simply isn't being attached to the request (missing header, wrong header name)
How to fix it
- Fetch a fresh token per test (or per suite) instead of reusing one long-lived token across a whole run
- Log the actual outgoing `Authorization` header in a failing case to rule out a wiring bug before suspecting expiry
- If tests run in parallel, give each one its own auth session instead of sharing one