samedi 25 août 2018

Can't decide how to test this code

I am attempting to write a test for the following code using mocha, chai, chai as promised & sinon but I am not too familiar with testing and have reached a mental wall.

const PasswordResets = require('../../../models/password-resets');
const ResponseError = require('../../../error-handlers/response-error');

function updatePasswordReset(email, token, doc = null) {
    return new Promise((resolve, reject) => {

        // If reset token already exists set it as the token
        if (doc !== null) {
           doc.token = token;
        }

        var passwordReset = doc === null ? new PasswordResets({ email, token }) : doc;

        passwordReset.save(function (err, document) {
            if (err) {
                return reject(new ResponseError(err.message));
            }

           resolve(document);
       });
    });
}

module.exports = updatePasswordReset;

Any help would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire