Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
creating a mock JWT token for testing

I'm trying to create a test that will test the following branch.

if (req.body.sessionToken) {
  let sessionToken = req.body.sessionToken;
  let tokenData = jwt.verify(sessionToken,config.secretSessionKey);
  sessionID = tokenData.sessionID;
}

I tried creating a mock JSON response containing a sessionToken key with a random value that will be sent but I'm getting a UnauthorizedError: jwt malformed error. I believe that I only have to provide the mock sessionToken in the right format to run the test since based on the test coverage, I'm getting the error on the

let sessionTokenData = jwt.verify(sessionToken,config.secretSessionKey);

but I have to idea how should it be written.

Here is a part of my test. I'm calling the /authenticate endpoint then sending the sessionToken JSON that will contain the mock sessionToken value.

 return request
  .post("/authenticate")
  .send(sessionToken)
  .then(response => {
    let body = JSON.parse(response.text); })
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!