https://supertokens.com/ logo
Title
a

Arne

11/11/2022, 6:07 AM
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

rp

11/11/2022, 6:14 AM
a

Arne

11/11/2022, 6:15 AM
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:
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:
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

rp

11/25/2022, 8:04 AM
preflight is a call to the OPTIONS API.
You want to return a 200 from the OPTIONS APi call with the right headers
a

Arne

11/25/2022, 8:19 AM
Sorry, to make this clearer, this would be the call that I am testing for the auth api:
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

rp

11/25/2022, 8:20 AM
preflight usually refers to an OPTIONS APi call
a

Arne

11/25/2022, 8:25 AM
I guess it is a supertest issue. When I run in my terminal:
curl --location --request GET 'http://localhost:3331/auth/signup/email/exists?email=arne.wolframm@gmail.com'
I get
{
  "exists": true,
  "status": "OK"
}
When I use the above supertest, I get 401
This also works:
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

rp

11/25/2022, 8:36 AM
hey @Arne i'll have to get back to you about pricing on monday
a

Arne

11/25/2022, 8:36 AM
OK
a

Adiboi

11/25/2022, 2:54 PM
Hi Arne. We'd share some pricing after our last call. Did you have any thoughts around that?