mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
mock for emailer for resetPassword route
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../../../helpers/api-integration/v3';
|
} from '../../../../helpers/api-integration/v3';
|
||||||
|
|
||||||
describe('POST /user/reset-password', async () => {
|
describe('POST /user/reset-password', async () => {
|
||||||
let endpoint = '/user/reset-password';
|
let endpoint = '/user/reset-password';
|
||||||
@@ -11,21 +11,19 @@ describe('POST /user/reset-password', async () => {
|
|||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
it('resets password', async () => {
|
it('resets password', async () => {
|
||||||
let response = await user.post(endpoint, {
|
let response = await user.post(endpoint, {
|
||||||
email: user.auth.local.email,
|
email: user.auth.local.email,
|
||||||
});
|
});
|
||||||
expect(response).to.eql({code: 200, message: t('passwordReset')});
|
expect(response).to.eql({ message: t('passwordReset') });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('same message on error as on success', async () => {
|
it('same message on error as on success', async () => {
|
||||||
let response = await user.post(endpoint, {
|
let response = await user.post(endpoint, {
|
||||||
email: 'nonExistent@email.com',
|
email: 'nonExistent@email.com',
|
||||||
});
|
});
|
||||||
expect(response).to.eql({code: 200, message: t('passwordReset')});
|
expect(response).to.eql({ message: t('passwordReset') });
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
it('errors if email is not provided', async () => {
|
it('errors if email is not provided', async () => {
|
||||||
await expect(user.post(endpoint)).to.eventually.be.rejected.and.eql({
|
await expect(user.post(endpoint)).to.eventually.be.rejected.and.eql({
|
||||||
@@ -96,6 +96,9 @@ api.resetPassword = {
|
|||||||
middlewares: [],
|
middlewares: [],
|
||||||
url: '/user/reset-password',
|
url: '/user/reset-password',
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
|
|
||||||
|
console.log('is prod is:', nconf.get('IS_PROD'));
|
||||||
|
|
||||||
req.checkBody({
|
req.checkBody({
|
||||||
email: {
|
email: {
|
||||||
notEmpty: {errorMessage: res.t('missingEmail')},
|
notEmpty: {errorMessage: res.t('missingEmail')},
|
||||||
|
|||||||
@@ -25,9 +25,13 @@ let smtpTransporter = createTransport({
|
|||||||
// Send email directly from the server using the smtpTransporter,
|
// Send email directly from the server using the smtpTransporter,
|
||||||
// used only to send password reset emails because users unsubscribed on Mandrill wouldn't get them
|
// used only to send password reset emails because users unsubscribed on Mandrill wouldn't get them
|
||||||
export function send (mailData) {
|
export function send (mailData) {
|
||||||
|
if (IS_PROD) {
|
||||||
return smtpTransporter
|
return smtpTransporter
|
||||||
.sendMail(mailData)
|
.sendMail(mailData)
|
||||||
.catch((error) => logger.error(error));
|
.catch((error) => logger.error(error));
|
||||||
|
} else {
|
||||||
|
return { send: () => {} } // mock
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUserInfo (user, fields = []) {
|
export function getUserInfo (user, fields = []) {
|
||||||
|
|||||||
Reference in New Issue
Block a user