Hello. Can someone tell me how to create SuperToke...
# share-your-work
b
Hello. Can someone tell me how to create SuperTokens userIds for testing purposes?
r
hey @busterbyron
You would need to go through the login process in your tests in order to create supertokens user IDs for testing - which recipe are you using?
b
Oh, ok. I'm ThirdPartyEmailPassword, just for email password + email verification
r
Are you talking about automated tests or manual tests? For automated tests, you can checkout how we do testing on our backend SDK. That should help out
b
Yeah, I'm running automated tests. That sounds great, I will check that out. Thank you!
Hi again. I'm trying to test auth-protected routes in an express app using Jest and supertest to mock requests. I created a supertokens user with emailPasswordSignup, and I used user.id from that to make a session with createNewSession. Now I'm having two problems I hope you can help me with.
First, I got the access token from the session and tried to attach it as a cookie to supertest (aka, "request") like so: await request(server) .post(testedRoute) .set("Cookie", [
sAccessToken=${accessToken}
]) .send(body); This gives an error that I don't understand: "Error while setting header with key: front-token and value: eyJ1aWQiOiIyN2UxYjAyNy0xMGU4LTQ0ZjEtOTg4OS05OTJjYTY0MTIyOTUiLCJhdGUiOjE2NTk3OTE1MzQwMjksInVwIjp7fX0="
And second, my understanding is that for the request to be valid, I will also need to send a refresh token and anti-csrf token, with this type of format and keys: tokens = { cookies: { sAccessToken, sIdRefreshToken }, headers: { anti-csrf } } I'm not sure how to get those other two tokens from the session, though.
I feel like I'm probably conceptualizing this process totally wrong. Any tips are greatly appreciated. And for what it's worth, everything works great when I manually test. Supertokens is awesome
r
Hey! So you need access token and idRefreshToken to be sent for verifySession to work. Refresh token is only meant for refresh api, but that should be irrelevant for tests anyway
b
Ah, ok. The route I'm testing uses verifySession, so maybe I'm just missing the idRefreshToken. Can you tell me how to get that or produce one? I don't see a method for it on the session object
r
You can get these from the set-cookie header in the response from the api call for login
6 Views