Node.js based forum software built for the modern web
fix(emails): registration tests, email no longer passed-in, API tests (confirm email for test accounts)
Julian Lam6694bdd5502c
diff --git a/test/api.js b/test/api.jsindex 7b40145bcb..38d16e45cc 100644--- a/test/api.js+++ b/test/api.js@@ -111,6 +111,9 @@ describe('API', async () => {// Create sample usersconst 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.email.confirmByUid(adminUid);+ await user.email.confirmByUid(unprivUid);+for (let x = 0; x < 4; x++) {// eslint-disable-next-line no-await-in-loopawait user.create({ username: 'deleteme', password: '123456' }); // for testing of DELETE /users (uids 5, 6) and DELETE /user/:uid/account (uid 7)diff --git a/test/authentication.js b/test/authentication.jsindex ce92392d9d..8a8d5886e4 100644--- a/test/authentication.js+++ b/test/authentication.js@@ -44,36 +44,6 @@ describe('authentication', () => {}const loginUserPromisified = util.promisify(loginUser);- function registerUser(email, username, password, callback) {- const jar = request.jar();- request({- url: `${nconf.get('url')}/api/config`,- json: true,- jar: jar,- }, (err, response, body) => {- if (err) {- return callback(err);- }-- request.post(`${nconf.get('url')}/register`, {- form: {- email: email,- username: username,- password: password,- 'password-confirm': password,- gdpr_consent: true,- },- json: true,- jar: jar,- headers: {- 'x-csrf-token': body.csrf_token,- },- }, (err, response, body) => {- callback(err, response, body, jar);- });- });- }-const jar = request.jar();let regularUid;before((done) => {@@ -88,8 +58,6 @@ describe('authentication', () => {helpers.registerUser({username: 'a',password: '123456',- 'password-confirm': '123456',- email: '[email protected]',}, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 400);@@ -102,8 +70,6 @@ describe('authentication', () => {helpers.registerUser({username: '----a-----',password: '123456',- 'password-confirm': '123456',- email: '[email protected]',}, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 400);@@ -116,8 +82,6 @@ describe('authentication', () => {helpers.registerUser({username: ' a',password: '123456',- 'password-confirm': '123456',- email: '[email protected]',}, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 400);@@ -130,8 +94,6 @@ describe('authentication', () => {helpers.registerUser({username: 'a ',password: '123456',- 'password-confirm': '123456',- email: '[email protected]',}, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 400);@@ -140,7 +102,6 @@ describe('authentication', () => {});});-it('should register and login a user', (done) => {request({url: `${nconf.get('url')}/api/config`,@@ -360,7 +321,10 @@ describe('authentication', () => {it('should fail to register if registraton is disabled', (done) => {meta.config.registrationType = 'disabled';- registerUser('[email protected]', 'someuser', 'somepassword', (err, response, body) => {+ helpers.registerUser({+ username: 'someuser',+ password: 'somepassword',+ }, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 403);assert.equal(body, 'Forbidden');@@ -370,7 +334,10 @@ describe('authentication', () => {it('should return error if invitation is not valid', (done) => {meta.config.registrationType = 'invite-only';- registerUser('[email protected]', 'someuser', 'somepassword', (err, response, body) => {+ helpers.registerUser({+ username: 'someuser',+ password: 'somepassword',+ }, (err, jar, response, body) => {meta.config.registrationType = 'normal';assert.ifError(err);assert.equal(response.statusCode, 400);@@ -379,21 +346,18 @@ describe('authentication', () => {});});- it('should fail to register if email is falsy', (done) => {- registerUser('', 'someuser', 'somepassword', (err, response, body) => {- assert.ifError(err);- assert.equal(response.statusCode, 400);- assert.equal(body, '[[error:invalid-email]]');- done();- });- });-it('should fail to register if username is falsy or too short', (done) => {- registerUser('[email protected]', '', 'somepassword', (err, response, body) => {+ helpers.registerUser({+ username: '',+ password: 'somepassword',+ }, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 400);assert.equal(body, '[[error:username-too-short]]');- registerUser('[email protected]', 'a', 'somepassword', (err, response, body) => {+ helpers.registerUser({+ username: 'a',+ password: 'somepassword',+ }, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 400);assert.equal(body, '[[error:username-too-short]]');@@ -403,7 +367,10 @@ describe('authentication', () => {});it('should fail to register if username is too long', (done) => {- registerUser('[email protected]', 'thisisareallylongusername', '123456', (err, response, body) => {+ helpers.registerUser({+ username: 'thisisareallylongusername',+ password: '123456',+ }, (err, jar, response, body) => {assert.ifError(err);assert.equal(response.statusCode, 400);assert.equal(body, '[[error:username-too-long]]');@@ -413,7 +380,12 @@ describe('authentication', () => {it('should queue user if ip is used before', (done) => {meta.config.registrationApprovalType = 'admin-approval-ip';- registerUser('[email protected]', 'anotheruser', 'anotherpwd', (err, response, body) => {+ helpers.registerUser({+ email: '[email protected]',+ username: 'anotheruser',+ password: 'anotherpwd',+ gdpr_consent: 1,+ }, (err, jar, response, body) => {meta.config.registrationApprovalType = 'normal';assert.ifError(err);assert.equal(response.statusCode, 200);@@ -423,15 +395,11 @@ describe('authentication', () => {});- it('should be able to login with email', (done) => {- user.create({ username: 'ginger', password: '123456', email: '[email protected]' }, (err) => {- assert.ifError(err);- loginUser('[email protected]', '123456', (err, response) => {- assert.ifError(err);- assert.equal(response.statusCode, 200);- done();- });- });+ it('should be able to login with email', async () => {+ const uid = await user.create({ username: 'ginger', password: '123456', email: '[email protected]' });+ await user.email.confirmByUid(uid);+ const response = await loginUserPromisified('[email protected]', '123456');+ assert.equal(response.statusCode, 200);});it('should fail to login if login type is username and an email is sent', (done) => {diff --git a/test/helpers/index.js b/test/helpers/index.jsindex 0e38e23c5d..6f9710faf7 100644--- a/test/helpers/index.js+++ b/test/helpers/index.js@@ -125,6 +125,10 @@ helpers.registerUser = function (data, callback) {return callback(err);}+ if (!data.hasOwnProperty('password-confirm')) {+ data['password-confirm'] = data.password;+ }+request.post(`${nconf.get('url')}/register`, {form: data,json: true,