supertokens-auth-react
supertokens-auth-react copied to clipboard
Any easy way to mock out sessions?
Hi, we're creating tests for one of our web applications, and there doesn't seem to be an easy way to mock out Sessions where SessionAuth
HoC is respected.
While we can mock out the auth endpoints, I'm not so sure how to mock out the actual session response. If we cannot mock out the actual session, then the SessionAuth
HoC will block us from testing other components. Plus, we'd like to actually test Auth flows
https://github.com/supertokens/supertokens-core/issues/115 recommends spinning up a local supertokenscore with inmemory db, however, this is really cumberstone and complex for our use case.
What you can do is to override the session recipe functions on the frontend like doesSessionExist
or getAccessTokenPayloadSecurely
etc to return mocked information if it's testing env. This should solve your issue
Do you have an example?
I'm not too familiar with the AuthSession component and what it uses for valid session.
We don't have a specific example for this, but do checkout this: https://supertokens.com/docs/session/advanced-customizations/frontend-functions-override/usage
You need to override all the session recipe functions like doesSessionExist
and return the appropriate values from the functions.