Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any easy way to mock out sessions? #694

Open
nodiesBlade opened this issue May 14, 2023 · 3 comments
Open

Any easy way to mock out sessions? #694

nodiesBlade opened this issue May 14, 2023 · 3 comments

Comments

@nodiesBlade
Copy link

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

supertokens/supertokens-core#115 recommends spinning up a local supertokenscore with inmemory db, however, this is really cumberstone and complex for our use case.

@rishabhpoddar
Copy link
Contributor

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

@nodiesBlade
Copy link
Author

nodiesBlade commented May 15, 2023

Do you have an example?

I'm not too familiar with the AuthSession component and what it uses for valid session.

@rishabhpoddar
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants