Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda