Hi! I would like to programmatically (and locally...
# support-questions
a
Hi! I would like to programmatically (and locally) test the ST backend SDK (Nodejs) for signing up multiple users (passwordless) and setting user roles. I would also need to programmatically sign-in to simulate being a specific user with a specific role. Could you point me to a guide/example or just give some hints where to start?
r
a
Thanks!
Hi @rp, while I am able to test ST using Postman or Curl (by manually starting my server and ST core locally), I have not managed to get it to work with Supertest. When I just run a plain Express server, Supertest works. Then I add the SuperTokens-specific code snippets to my server and run the following simple test:
Copy code
test("get local tests working", async () => {
  const response = await supertest(getApp(SubDomain.mgmt)).get("/api");
  expect(response.status).toEqual(200);
});
While the response is still 200, the console print the following error message:
Copy code
Error: Error: Response for preflight has invalid HTTP status code 401
        at Object.dispatchError (/Users/arnewolframm/retality/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19)
        at EventEmitter.<anonymous> (/Users/arnewolframm/retality/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
        at EventEmitter.emit (node:events:525:35)
        at EventEmitter.emit (node:domain:489:12)
        ...etc...
What might I be doing wrong in the setup?
r
preflight is a call to the OPTIONS API.
You want to return a 200 from the OPTIONS APi call with the right headers
a
Sorry, to make this clearer, this would be the call that I am testing for the auth api:
Copy code
await supertest(getApp(SubDomain.mgmt))
    .get("/auth/signup/email/exists")
    .query("email=arne.wolframm@gmail.com");
I don't think any additional headers are needed?
r
preflight usually refers to an OPTIONS APi call
a
I guess it is a supertest issue. When I run in my terminal:
Copy code
curl --location --request GET 'http://localhost:3331/auth/signup/email/exists?email=arne.wolframm@gmail.com'
I get
Copy code
{
  "exists": true,
  "status": "OK"
}
When I use the above supertest, I get 401
This also works:
Copy code
const response = await supertest.agent("http://localhost:3331")
    .get("/auth/signup/email/exists")
    .query("email=arne.wolframm@gmail.com");
I seem to get the error when I let supertest actually start the server by passing the Express app to it.
Is it possible to get some paid support time to help me setup the testing?
r
hey @Arne i'll have to get back to you about pricing on monday
a
OK
a
Hi Arne. We'd share some pricing after our last call. Did you have any thoughts around that?