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
|
||||
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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
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;
|
||||
});
|
||||
|
||||
|
||||
|
||||
51
test/user.js
51
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, '<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.reputation, 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' });
|
||||
uid = newUid;
|
||||
|
||||
await User.setUserField(uid, 'email', 'update@me.com');
|
||||
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: 'just@for.updated', password: '123456' });
|
||||
await User.setUserField(uid, 'email', 'just@for.updated');
|
||||
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: 'notaninviter@nodebb.org' }),
|
||||
inviter: async.apply(User.create, { username: 'inviter', password: COMMON_PW, email: 'inviter@nodebb.org' }),
|
||||
admin: async.apply(User.create, { username: 'adminInvite', password: COMMON_PW }),
|
||||
}, (err, results) => {
|
||||
assert.ifError(err);
|
||||
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;
|
||||
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);
|
||||
});
|
||||
|
||||
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', () => {
|
||||
@@ -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 = 'confirm2@me.com';
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user