Skip to main content
@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.
Each call generates unique IDs, so you can create multiple entities in the same test without collisions.

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 the x-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 narrow ActionResult<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.
Last modified on April 29, 2026