All files / src resend-verify-signup.js

100% Statements 17/17
100% Branches 2/2
100% Functions 1/1
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35  1x 1x 1x 1x 1x 1x   1x       1x 77x 77x 77x   77x       69x 69x   45x             45x 45x    
 
const makeDebug = require('debug');
const ensureObjPropsValid = require('./helpers/ensure-obj-props-valid');
const getLongToken = require('./helpers/get-long-token');
const getShortToken = require('./helpers/get-short-token');
const getUserData = require('./helpers/get-user-data');
const notifier = require('./helpers/notifier');
 
const debug = makeDebug('authLocalMgnt:resendVerifySignup');
 
// {email}, {cellphone}, {verifyToken}, {verifyShortToken},
// {email, cellphone, verifyToken, verifyShortToken}
module.exports = async function resendVerifySignup (options, identifyUser, notifierOptions = {}, params = {}) {
  debug('identifyUser=', identifyUser);
  const usersService = options.app.service(options.service);
  const usersServiceIdName = usersService.id;
 
  ensureObjPropsValid(identifyUser,
    options.identifyUserProps.concat('verifyToken', 'verifyShortToken')
  );
 
  const users = await usersService.find({ ...params, query: identifyUser });
  const user1 = getUserData(users, ['isNotVerified']);
 
  const user2 = await usersService.patch(user1[usersServiceIdName], {
    isVerified: false,
    verifyExpires: Date.now() + options.delay,
    verifyToken: await getLongToken(options.longTokenLen),
    verifyShortToken: await getShortToken(options.shortTokenLen, options.shortTokenDigits)
  }, params);
 
  const user3 = await notifier(options.notifier, 'resendVerifySignup', user2, notifierOptions);
  return options.sanitizeUserForClient(user3);
};