Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda