E2E testing backend (NESTJS)
# support-questions-legacy
j
Hi everyone, I'm currently trying to figure out a way to either mock or integrate supertoken into my backend e2e tests. I would like to have roles and permissions mechanics taken into account whenever I test an endpoint. Any ideas or even implementation examples on a repo ? thanks in advance
r
hey. In your tests, you can call the login endpoint to create a new session and then take it from there. In terms of the core, you can spin up a new docker container for each test suit with the in memory db and can restart the docker container during each test (to start from a fresh user table for each test), or can create new randomised users during each test.
there is no perfect solution to this yet, so it will likely be annoying
finally, you can see our github repo's test code for inspiration based on the SDKs that you use
j
I don't want to involve frontend client at all, it's really just testing calls on api endpoints
booting and restarting a ST instance for EACH test seems like a huge overhead
especially when the project starts scaling and you have 50 controllers and 10-20 test cases per controller
that would take an hour or more to launch the e2e test suite alone
which is a huge cost in terms of CI time
I'm honestly considering to look for another alternative
because that's kind of a deal breaker
I cannot spend months or years working on an API and not being able to test it properly within a reasonable amount of time
I feel like all the development time gained with supertokens initialy, is actually being paid for when you get onto testing
which makes me sad, because the project seems very promising
I'll give your testing solution a try and I'll let you know if this is a viable solution
10 seconds average to restart the container....
I'm gonna have to move to keycloak sadly
it would take too much dev time and would be too costly for me to spend time trying to write proper mocks
r
hey @joemckrusty - you could keep the container started and in each test, create a different user to login. This would remove the restart time for each test entirely.
Is testing via keycloak any different? It would have the same issue?
6 Views