• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

287
Views
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 3 years ago · Santiago Trujillo
1 answers
Answer question

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 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error