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

327
Visualizações
mocha : testing a signup process with email-verification framework

I try to test my signup router post function which use email-verification framework,but mocha shows me the error message below : TypeError: Cannot read property 'findOne' of null

This my code :

function that invoke the error:

nev.resendVerificationEmail(email,(err,userExist) =>{
if(err){
      return res.status(404).send('Error : resending verification email failed');}
if(userExist){
      res.json({message : 'An email has been sent to you , again. Please check it to verify your account'});
}else{
      res.json({message : 'Your verification code has expired . Please sign up again'});

and this is the implementation of resendVerificationEmail function

var resendVerificationEmail = function(email, callback) {
var query = {};
query[options.emailFieldName] = email;

options.tempUserModel.findOne(query, function(err, tempUser) { //this the error handler I guess
  if (err) {
    return callback(err, null);
  }

  // user found (i.e. user re-requested verification email before expiration)
  if (tempUser) {
    // generate new user token
    tempUser[options.URLFieldName] = randtoken.generate(options.URLLength);
    tempUser.save(function(err) {
      if (err) {
        return callback(err, null);
      }

      sendVerificationEmail(getNestedValue(tempUser, options.emailFieldName), tempUser[options.URLFieldName], function(err) {
        if (err) {
          return callback(err, null);
        }
        return callback(null, true);
      });
    });

  } else {
    return callback(null, false);
  }
});

};

and this is my spec

describe(' SignUp : /POST Test with fake client request : ', () => {
    let req, res, statusCode, sendData,user;
    beforeEach((done) => {
        SignupModal.remove({}, (err) => {
            done();
        });

        user = {
            firstName : 'ben',
            secondName : 'wissem',
            username : 'wiss',
            email : 'xy@zt.sq',
            password : 'wissem'
        };
        res = {
            json: function (code, data) {
                statusCode = code;
                sendData = data;
            }
        };
    });

    it('should send 200 code', () => {
        chai.request(server)
            .post('/user/signup')
            .send(user)
            .end((err, res) => {
                res.statusCode.should.equal(200);
            });
    });

Can any one help me please ?!

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

if you want to end-to-end test email verification try EmailE2E.com, it's a free API that let's you send and receive emails from randomly generated inboxes. It's perfect for Firebase, Amazon Cognito, or other OAuth providers that use email verification codes during sign up. It also has a Javascript client you can use with Mocha.

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