diff --git a/test/api.js b/test/api.js index ef192969fc..ad3bcadfad 100644 --- a/test/api.js +++ b/test/api.js @@ -111,6 +111,8 @@ describe('API', async () => { // Create sample users const adminUid = await user.create({ username: 'admin', password: '123456', email: 'test@example.org' }); const unprivUid = await user.create({ username: 'unpriv', password: '123456', email: 'unpriv@example.org' }); + await user.setUserField(adminUid, 'email', 'test@example.org'); + await user.setUserField(unprivUid, 'email', 'unpriv@example.org'); await user.email.confirmByUid(adminUid); await user.email.confirmByUid(unprivUid); diff --git a/test/authentication.js b/test/authentication.js index 82b445a04e..b8889d95eb 100644 --- a/test/authentication.js +++ b/test/authentication.js @@ -115,7 +115,9 @@ describe('authentication', () => { headers: { 'x-csrf-token': body.csrf_token, }, - }, (err, response, body) => { + }, async (err, response, body) => { + const validationPending = await user.email.isValidationPending(body.uid, 'admin@nodebb.org'); + assert.strictEqual(validationPending, true); assert.ifError(err); assert(body); assert(body.hasOwnProperty('uid') && body.uid > 0); @@ -128,7 +130,6 @@ describe('authentication', () => { assert.ifError(err); assert(body); assert.equal(body.username, 'admin'); - assert.equal(body.email, 'admin@nodebb.org'); assert.equal(body.uid, newUid); user.getSettings(body.uid, (err, settings) => { assert.ifError(err); @@ -387,7 +388,9 @@ describe('authentication', () => { it('should be able to login with email', async () => { - const uid = await user.create({ username: 'ginger', password: '123456', email: 'ginger@nodebb.org' }); + const email = 'ginger@nodebb.org'; + const uid = await user.create({ username: 'ginger', password: '123456', email }); + await user.setUserField(uid, 'email', email); await user.email.confirmByUid(uid); const { res } = await helpers.loginUser('ginger@nodebb.org', '123456'); assert.equal(res.statusCode, 200); diff --git a/test/controllers.js b/test/controllers.js index 0e1045148e..de7f95b4fb 100644 --- a/test/controllers.js +++ b/test/controllers.js @@ -483,7 +483,8 @@ describe('Controllers', () => { }); it('should remove current email', async () => { - const uid = await user.create({ username: 'interstiuser5', email: 'interstiuser5@nodebb.org' }); + const uid = await user.create({ username: 'interstiuser5' }); + await user.setUserField(uid, 'email', 'interstiuser5@nodebb.org'); await user.email.confirmByUid(uid); const result = await user.interstitials.email({ diff --git a/test/socket.io.js b/test/socket.io.js index e38777c1b3..d56a5b9a82 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -32,24 +32,23 @@ describe('socket.io', () => { let adminUid; let regularUid; - before((done) => { - async.series([ - async.apply(user.create, { username: 'admin', password: 'adminpwd' }), - async.apply(user.create, { username: 'regular', password: 'regularpwd', email: 'regular@test.com' }), - async.apply(categories.create, { + before(async () => { + const data = await Promise.all([ + user.create({ username: 'admin', password: 'adminpwd' }), + user.create({ username: 'regular', password: 'regularpwd' }), + categories.create({ name: 'Test Category', description: 'Test category created by testing script', }), - ], (err, data) => { - if (err) { - return done(err); - } - adminUid = data[0]; - regularUid = data[1]; - cid = data[2].cid; + ]); + adminUid = data[0]; + await groups.join('administrators', data[0]); - groups.join('administrators', data[0], done); - }); + regularUid = data[1]; + await user.setUserField(regularUid, 'email', 'regular@test.com'); + await user.email.confirmByUid(regularUid); + + cid = data[2].cid; }); diff --git a/test/user.js b/test/user.js index 63f200f198..f8e09d7493 100644 --- a/test/user.js +++ b/test/user.js @@ -23,6 +23,7 @@ const meta = require('../src/meta'); const file = require('../src/file'); const socketUser = require('../src/socket.io/user'); const apiUser = require('../src/api/users'); +const utils = require('../src/utils'); describe('User', () => { let userData; @@ -82,7 +83,11 @@ describe('User', () => { it('should be created properly', async () => { const uid = await User.create({ username: 'weirdemail', email: '