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

153
Visualizações
Mocking Passport authentication on protected endpoints

I'm using passport local strategy to authenticate users and I'm having issues with continuous integration testing on protected endpoints. I used this tutorial to get my authentication up and running. I'm using mocha/chai for testing and I can't figure out how to test an endpoint with a user logged during testing. I understand that I may have to use a mock strategy but I'm not sure how to do that. Here is an example endpoint, I need the user to be logged in so that I have access to the req.user.id variable that gets set when I a user is logged in.

router.post('/user/draft/delete', (req, res) => {
if(!req.user) {
    return res.redirect('/login');
}

User
    .findById(req.user.id)
    .exec()
    .then(user => {
        user.drafts.pull(req.body.draftid);
        user.save();
        res.status(202).redirect('/dashboard');
    })
    .catch(err => {
        console.error(err);
        res.status(500).redirect('/dashboard');
    });
});

I'm not sure what other information might be required but I'm happy to update this post with any code needed.

about 4 years ago · Santiago Trujillo
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