From 27b030a71c64b43796ae3a3ced6fa06f698cdb7b Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 11 Mar 2017 16:43:19 +0300 Subject: [PATCH] test for #5523 --- src/middleware/header.js | 2 +- src/user/email.js | 3 +++ test/user.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/middleware/header.js b/src/middleware/header.js index e5d4de66bb..70c0755def 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -82,7 +82,7 @@ module.exports = function (middleware) { picture: meta.config.defaultAvatar, status: 'offline', reputation: 0, - 'email:confirmed': false, + 'email:confirmed': 0, }; if (req.uid) { user.getUserFields(req.uid, Object.keys(userData), next); diff --git a/src/user/email.js b/src/user/email.js index f75ff9cf9b..e7411685e6 100644 --- a/src/user/email.js +++ b/src/user/email.js @@ -83,6 +83,9 @@ var emailer = require('../emailer'); } }); }, + function (next) { + next(null, confirm_code); + }, ], callback); }; diff --git a/test/user.js b/test/user.js index 468ab9b0b4..c956bfdcde 100644 --- a/test/user.js +++ b/test/user.js @@ -1152,6 +1152,45 @@ describe('User', function () { }); }); + describe('email confirm', function () { + it('should error with invalid code', function (done) { + User.email.confirm('asdasda', function (err) { + assert.equal(err.message, '[[error:invalid-data]]'); + done(); + }); + }); + + it('should confirm email of user', function (done) { + var email = 'confirm@me.com'; + User.create({ + username: 'confirme', + email: email, + }, function (err, uid) { + assert.ifError(err); + User.email.sendValidationEmail(uid, email, function (err, code) { + assert.ifError(err); + User.email.confirm(code, function (err) { + assert.ifError(err); + + async.parallel({ + confirmed: function (next) { + db.getObjectField('user:' + uid, 'email:confirmed', next); + }, + isMember: function (next) { + db.isSortedSetMember('users:notvalidated', uid, next); + }, + }, function (err, results) { + assert.ifError(err); + assert.equal(results.confirmed, 1); + assert.equal(results.isMember, false); + done(); + }); + }); + }); + }); + }); + }); + after(function (done) { db.emptydb(done);