mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
test: fix tests so that when user.create is called, email is set prior to confirmation
This commit is contained in:
@@ -111,6 +111,8 @@ describe('API', async () => {
|
|||||||
// Create sample users
|
// Create sample users
|
||||||
const adminUid = await user.create({ username: 'admin', password: '123456', email: 'test@example.org' });
|
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' });
|
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(adminUid);
|
||||||
await user.email.confirmByUid(unprivUid);
|
await user.email.confirmByUid(unprivUid);
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,9 @@ describe('authentication', () => {
|
|||||||
headers: {
|
headers: {
|
||||||
'x-csrf-token': body.csrf_token,
|
'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.ifError(err);
|
||||||
assert(body);
|
assert(body);
|
||||||
assert(body.hasOwnProperty('uid') && body.uid > 0);
|
assert(body.hasOwnProperty('uid') && body.uid > 0);
|
||||||
@@ -128,7 +130,6 @@ describe('authentication', () => {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(body);
|
assert(body);
|
||||||
assert.equal(body.username, 'admin');
|
assert.equal(body.username, 'admin');
|
||||||
assert.equal(body.email, 'admin@nodebb.org');
|
|
||||||
assert.equal(body.uid, newUid);
|
assert.equal(body.uid, newUid);
|
||||||
user.getSettings(body.uid, (err, settings) => {
|
user.getSettings(body.uid, (err, settings) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@@ -387,7 +388,9 @@ describe('authentication', () => {
|
|||||||
|
|
||||||
|
|
||||||
it('should be able to login with email', async () => {
|
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);
|
await user.email.confirmByUid(uid);
|
||||||
const { res } = await helpers.loginUser('ginger@nodebb.org', '123456');
|
const { res } = await helpers.loginUser('ginger@nodebb.org', '123456');
|
||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
|
|||||||
@@ -483,7 +483,8 @@ describe('Controllers', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should remove current email', async () => {
|
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);
|
await user.email.confirmByUid(uid);
|
||||||
|
|
||||||
const result = await user.interstitials.email({
|
const result = await user.interstitials.email({
|
||||||
|
|||||||
@@ -32,24 +32,23 @@ describe('socket.io', () => {
|
|||||||
let adminUid;
|
let adminUid;
|
||||||
let regularUid;
|
let regularUid;
|
||||||
|
|
||||||
before((done) => {
|
before(async () => {
|
||||||
async.series([
|
const data = await Promise.all([
|
||||||
async.apply(user.create, { username: 'admin', password: 'adminpwd' }),
|
user.create({ username: 'admin', password: 'adminpwd' }),
|
||||||
async.apply(user.create, { username: 'regular', password: 'regularpwd', email: 'regular@test.com' }),
|
user.create({ username: 'regular', password: 'regularpwd' }),
|
||||||
async.apply(categories.create, {
|
categories.create({
|
||||||
name: 'Test Category',
|
name: 'Test Category',
|
||||||
description: 'Test category created by testing script',
|
description: 'Test category created by testing script',
|
||||||
}),
|
}),
|
||||||
], (err, data) => {
|
]);
|
||||||
if (err) {
|
adminUid = data[0];
|
||||||
return done(err);
|
await groups.join('administrators', data[0]);
|
||||||
}
|
|
||||||
adminUid = data[0];
|
|
||||||
regularUid = data[1];
|
|
||||||
cid = data[2].cid;
|
|
||||||
|
|
||||||
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;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
55
test/user.js
55
test/user.js
@@ -23,6 +23,7 @@ const meta = require('../src/meta');
|
|||||||
const file = require('../src/file');
|
const file = require('../src/file');
|
||||||
const socketUser = require('../src/socket.io/user');
|
const socketUser = require('../src/socket.io/user');
|
||||||
const apiUser = require('../src/api/users');
|
const apiUser = require('../src/api/users');
|
||||||
|
const utils = require('../src/utils');
|
||||||
|
|
||||||
describe('User', () => {
|
describe('User', () => {
|
||||||
let userData;
|
let userData;
|
||||||
@@ -82,7 +83,11 @@ describe('User', () => {
|
|||||||
it('should be created properly', async () => {
|
it('should be created properly', async () => {
|
||||||
const uid = await User.create({ username: 'weirdemail', email: '<h1>test</h1>@gmail.com' });
|
const uid = await User.create({ username: 'weirdemail', email: '<h1>test</h1>@gmail.com' });
|
||||||
const data = await User.getUserData(uid);
|
const data = await User.getUserData(uid);
|
||||||
assert.equal(data.email, '<h1>test</h1>@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.profileviews, 0);
|
||||||
assert.strictEqual(data.reputation, 0);
|
assert.strictEqual(data.reputation, 0);
|
||||||
assert.strictEqual(data.postcount, 0);
|
assert.strictEqual(data.postcount, 0);
|
||||||
@@ -813,6 +818,7 @@ describe('User', () => {
|
|||||||
const newUid = await User.create({ username: 'updateprofile', email: 'update@me.com', password: '123456' });
|
const newUid = await User.create({ username: 'updateprofile', email: 'update@me.com', password: '123456' });
|
||||||
uid = newUid;
|
uid = newUid;
|
||||||
|
|
||||||
|
await User.setUserField(uid, 'email', 'update@me.com');
|
||||||
await User.email.confirmByUid(uid);
|
await User.email.confirmByUid(uid);
|
||||||
|
|
||||||
({ jar } = await helpers.loginUser('updateprofile', '123456'));
|
({ jar } = await helpers.loginUser('updateprofile', '123456'));
|
||||||
@@ -850,6 +856,9 @@ describe('User', () => {
|
|||||||
|
|
||||||
it('should update a user\'s profile', async () => {
|
it('should update a user\'s profile', async () => {
|
||||||
uid = await User.create({ username: 'justforupdate', email: 'just@for.updated', password: '123456' });
|
uid = await User.create({ username: 'justforupdate', email: 'just@for.updated', password: '123456' });
|
||||||
|
await User.setUserField(uid, 'email', 'just@for.updated');
|
||||||
|
await User.email.confirmByUid(uid);
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
username: 'updatedUserName',
|
username: 'updatedUserName',
|
||||||
@@ -2085,26 +2094,27 @@ describe('User', () => {
|
|||||||
|
|
||||||
const COMMON_PW = '123456';
|
const COMMON_PW = '123456';
|
||||||
|
|
||||||
before((done) => {
|
before(async () => {
|
||||||
async.parallel({
|
const results = await utils.promiseParallel({
|
||||||
publicGroup: async.apply(groups.create, { name: PUBLIC_GROUP, private: 0 }),
|
publicGroup: groups.create({ name: PUBLIC_GROUP, private: 0 }),
|
||||||
privateGroup: async.apply(groups.create, { name: PRIVATE_GROUP, private: 1 }),
|
privateGroup: groups.create({ name: PRIVATE_GROUP, private: 1 }),
|
||||||
hiddenGroup: async.apply(groups.create, { name: HIDDEN_GROUP, hidden: 1 }),
|
hiddenGroup: groups.create({ name: HIDDEN_GROUP, hidden: 1 }),
|
||||||
notAnInviter: async.apply(User.create, { username: 'notAnInviter', password: COMMON_PW, email: 'notaninviter@nodebb.org' }),
|
notAnInviter: User.create({ username: 'notAnInviter', password: COMMON_PW }),
|
||||||
inviter: async.apply(User.create, { username: 'inviter', password: COMMON_PW, email: 'inviter@nodebb.org' }),
|
inviter: User.create({ username: 'inviter', password: COMMON_PW }),
|
||||||
admin: async.apply(User.create, { username: 'adminInvite', password: COMMON_PW }),
|
admin: 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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
notAnInviterUid = results.notAnInviter;
|
||||||
|
inviterUid = results.inviter;
|
||||||
|
adminUid = results.admin;
|
||||||
|
|
||||||
|
await User.setUserField(inviterUid, 'email', 'inviter@nodebb.org');
|
||||||
|
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', () => {
|
describe('when inviter is not an admin and does not have invite privilege', () => {
|
||||||
@@ -2465,7 +2475,7 @@ describe('User', () => {
|
|||||||
email: email,
|
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');
|
const unverified = await groups.isMember(uid, 'unverified-users');
|
||||||
assert.strictEqual(unverified, true);
|
assert.strictEqual(unverified, true);
|
||||||
await User.email.confirmByCode(code);
|
await User.email.confirmByCode(code);
|
||||||
@@ -2481,8 +2491,9 @@ describe('User', () => {
|
|||||||
const email = 'confirm2@me.com';
|
const email = 'confirm2@me.com';
|
||||||
const uid = await User.create({
|
const uid = await User.create({
|
||||||
username: 'confirme2',
|
username: 'confirme2',
|
||||||
email: email,
|
email,
|
||||||
});
|
});
|
||||||
|
await User.setUserField(uid, 'email', email);
|
||||||
|
|
||||||
const unverified = await groups.isMember(uid, 'unverified-users');
|
const unverified = await groups.isMember(uid, 'unverified-users');
|
||||||
assert.strictEqual(unverified, true);
|
assert.strictEqual(unverified, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user