@kavachos/test-utils provides factories, mock servers, and assertion helpers so you can test auth-dependent code without a real database or network.
Install
Factories
Factory functions create realistic mock entities with sensible defaults. Pass overrides for any fields relevant to the test.Mock auth server
createMockAuthServer returns an in-memory AuthAdapter implementation with zero network or database calls. Use it in server-side unit tests that exercise code paths calling resolveUser, getUser, or syncUser.
Per-request user override
Set thex-mock-kavach-user-id header on a Request to override the active user for that specific request only, without calling setActiveUser:
Cleanup
Assertions
Three typed assertion helpers narrowActionResult<T> and throw descriptive errors on failure.
The mock server has zero runtime dependencies. It matches the
AuthAdapter interface structurally, so TypeScript will accept it anywhere an AuthAdapter is expected.