Skip to content

Node.js based forum software built for the modern web

test: fix tests so that when user.create is called, email is set prior to confirmation

Julian Lamf93a0b83bbc7
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: '[email protected]' });
const unprivUid = await user.create({ username: 'unpriv', password: '123456', email: '[email protected]' });
+ await user.setUserField(adminUid, 'email', '[email protected]');
+ await user.setUserField(unprivUid, 'email', '[email protected]');
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, '[email protected]');
+ 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, '[email protected]');
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: '[email protected]' });
+ const email = '[email protected]';
+ 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('[email protected]', '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: '[email protected]' });
+ const uid = await user.create({ username: 'interstiuser5' });
+ await user.setUserField(uid, 'email', '[email protected]');
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: '[email protected]' }),
- 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', '[email protected]');
+ 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: '<h1>test</h1>@gmail.com' });
const data = await User.getUserData(uid);
- assert.equal(data.email, '&lt;h1&gt;test&lt;&#x2F;h1&gt;@gmail.com');
+
+ const validationPending = await User.email.isValidationPending(uid, '<h1>test</h1>@gmail.com');
+ assert.strictEqual(validationPending, true);
+
+ assert.equal(data.email, '');
assert.strictEqual(data.profileviews, 0);
assert.strictEqual(data.reputation, 0);
assert.strictEqual(data.postcount, 0);
@@ -813,6 +818,7 @@ describe('User', () => {
const newUid = await User.create({ username: 'updateprofile', email: '[email protected]', password: '123456' });
uid = newUid;
+ await User.setUserField(uid, 'email', '[email protected]');
await User.email.confirmByUid(uid);
({ jar } = await helpers.loginUser('updateprofile', '123456'));
@@ -850,6 +856,9 @@ describe('User', () => {
it('should update a user\'s profile', async () => {
uid = await User.create({ username: 'justforupdate', email: '[email protected]', password: '123456' });
+ await User.setUserField(uid, 'email', '[email protected]');
+ await User.email.confirmByUid(uid);
+
const data = {
uid: uid,
username: 'updatedUserName',
@@ -2085,26 +2094,27 @@ describe('User', () => {
const COMMON_PW = '123456';
- before((done) => {
- async.parallel({
- publicGroup: async.apply(groups.create, { name: PUBLIC_GROUP, private: 0 }),
- privateGroup: async.apply(groups.create, { name: PRIVATE_GROUP, private: 1 }),
- hiddenGroup: async.apply(groups.create, { name: HIDDEN_GROUP, hidden: 1 }),
- notAnInviter: async.apply(User.create, { username: 'notAnInviter', password: COMMON_PW, email: '[email protected]' }),
- inviter: async.apply(User.create, { username: 'inviter', password: COMMON_PW, email: '[email protected]' }),
- admin: async.apply(User.create, { username: 'adminInvite', password: COMMON_PW }),
- }, (err, results) => {
- assert.ifError(err);
- notAnInviterUid = results.notAnInviter;
- inviterUid = results.inviter;
- adminUid = results.admin;
- async.parallel([
- async.apply(groups.create, { name: OWN_PRIVATE_GROUP, ownerUid: inviterUid, private: 1 }),
- async.apply(groups.join, 'administrators', adminUid),
- async.apply(groups.join, 'cid:0:privileges:invite', inviterUid),
- async.apply(User.email.confirmByUid, inviterUid),
- ], done);
+ before(async () => {
+ const results = await utils.promiseParallel({
+ publicGroup: groups.create({ name: PUBLIC_GROUP, private: 0 }),
+ privateGroup: groups.create({ name: PRIVATE_GROUP, private: 1 }),
+ hiddenGroup: groups.create({ name: HIDDEN_GROUP, hidden: 1 }),
+ notAnInviter: User.create({ username: 'notAnInviter', password: COMMON_PW }),
+ inviter: User.create({ username: 'inviter', password: COMMON_PW }),
+ admin: User.create({ username: 'adminInvite', password: COMMON_PW }),
});
+
+ notAnInviterUid = results.notAnInviter;
+ inviterUid = results.inviter;
+ adminUid = results.admin;
+
+ await User.setUserField(inviterUid, 'email', '[email protected]');
+ await Promise.all([
+ groups.create({ name: OWN_PRIVATE_GROUP, ownerUid: inviterUid, private: 1 }),
+ groups.join('administrators', adminUid),
+ groups.join('cid:0:privileges:invite', inviterUid),
+ User.email.confirmByUid(inviterUid),
+ ]);
});
describe('when inviter is not an admin and does not have invite privilege', () => {
@@ -2465,7 +2475,7 @@ describe('User', () => {
email: email,
});
- const code = await User.email.sendValidationEmail(uid, email);
+ const code = await User.email.sendValidationEmail(uid, { email, force: 1 });
const unverified = await groups.isMember(uid, 'unverified-users');
assert.strictEqual(unverified, true);
await User.email.confirmByCode(code);
@@ -2481,8 +2491,9 @@ describe('User', () => {
const email = '[email protected]';
const uid = await User.create({
username: 'confirme2',
- email: email,
+ email,
});
+ await User.setUserField(uid, 'email', email);
const unverified = await groups.isMember(uid, 'unverified-users');
assert.strictEqual(unverified, true);