Node.js based forum software built for the modern web
refactor: get rid of async.waterfall/series
Barış Soner Uşaklı8bc2ef227ed4
diff --git a/test/groups.js b/test/groups.jsindex 2fcb48d59e..10ff138639 100644--- a/test/groups.js+++ b/test/groups.js@@ -1,7 +1,6 @@'use strict';const assert = require('assert');-const async = require('async');const fs = require('fs');const path = require('path');const nconf = require('nconf');@@ -161,33 +160,15 @@ describe('Groups', () => {});});- it('should return all users if no query', (done) => {- function createAndJoinGroup(username, email, callback) {- async.waterfall([- function (next) {- User.create({ username: username, email: email }, next);- },- function (uid, next) {- Groups.join('Test', uid, next);- },- ], callback);+ it('should return all users if no query', async () => {+ async function createAndJoinGroup(username, email) {+ const uid = await User.create({ username: username, email: email });+ await Groups.join('Test', uid);}- async.series([- function (next) {- createAndJoinGroup('newuser', '[email protected]', next);- },- function (next) {- createAndJoinGroup('bob', '[email protected]', next);- },- ], (err) => {- assert.ifError(err);-- socketGroups.searchMembers({ uid: adminUid }, { groupName: 'Test', query: '' }, (err, data) => {- assert.ifError(err);- assert.equal(data.users.length, 3);- done();- });- });+ await createAndJoinGroup('newuser', '[email protected]');+ await createAndJoinGroup('bob', '[email protected]');+ const data = await socketGroups.searchMembers({ uid: adminUid }, { groupName: 'Test', query: '' });+ assert.equal(data.users.length, 3);});it('should search group members', (done) => {@@ -584,37 +565,20 @@ describe('Groups', () => {});});- it('should remove group from privilege groups', (done) => {+ it('should remove group from privilege groups', async () => {const privileges = require('../src/privileges');const cid = 1;const groupName = '1';const uid = 1;- async.waterfall([- function (next) {- Groups.create({ name: groupName }, next);- },- function (groupData, next) {- privileges.categories.give(['groups:topics:create'], cid, groupName, next);- },- function (next) {- Groups.isMember(groupName, 'cid:1:privileges:groups:topics:create', next);- },- function (isMember, next) {- assert(isMember);- Groups.destroy(groupName, next);- },- function (next) {- Groups.isMember(groupName, 'cid:1:privileges:groups:topics:create', next);- },- function (isMember, next) {- assert(!isMember);- Groups.isMember(uid, 'registered-users', next);- },- function (isMember, next) {- assert(isMember);- next();- },- ], done);+ await Groups.create({ name: groupName });+ await privileges.categories.give(['groups:topics:create'], cid, groupName);+ let isMember = await Groups.isMember(groupName, 'cid:1:privileges:groups:topics:create');+ assert(isMember);+ await Groups.destroy(groupName);+ isMember = await Groups.isMember(groupName, 'cid:1:privileges:groups:topics:create');+ assert(!isMember);+ isMember = await Groups.isMember(uid, 'registered-users');+ assert(isMember);});});@@ -779,36 +743,19 @@ describe('Groups', () => {});describe('.leaveAllGroups()', () => {- it('should remove a user from all groups', (done) => {- Groups.leaveAllGroups(testUid, (err) => {- assert.ifError(err);-- const groups = ['Test', 'Hidden'];- async.every(groups, (group, next) => {- Groups.isMember(testUid, group, (err, isMember) => {- next(err, !isMember);- });- }, (err, result) => {- assert.ifError(err);- assert(result);-- done();- });- });+ it('should remove a user from all groups', async () => {+ await Groups.leaveAllGroups(testUid);+ const groups = ['Test', 'Hidden'];+ const isMembers = await Groups.isMemberOfGroups(testUid, groups);+ assert(!isMembers.includes(true));});});describe('.show()', () => {- it('should make a group visible', (done) => {- Groups.show('Test', function (err) {- assert.ifError(err);- assert.equal(arguments.length, 1);- db.isSortedSetMember('groups:visible:createtime', 'Test', (err, isMember) => {- assert.ifError(err);- assert.strictEqual(isMember, true);- done();- });- });+ it('should make a group visible', async () => {+ await Groups.show('Test');+ const isMember = await db.isSortedSetMember('groups:visible:createtime', 'Test');+ assert.strictEqual(isMember, true);});});@@ -1262,22 +1209,11 @@ describe('Groups', () => {let regularUid;const logoPath = path.join(__dirname, '../test/files/test.png');const imagePath = path.join(__dirname, '../test/files/groupcover.png');- before((done) => {- User.create({ username: 'regularuser', password: '123456' }, (err, uid) => {- assert.ifError(err);- regularUid = uid;- async.series([- function (next) {- Groups.join('Test', adminUid, next);- },- function (next) {- Groups.join('Test', regularUid, next);- },- function (next) {- helpers.copyFile(logoPath, imagePath, next);- },- ], done);- });+ before(async () => {+ regularUid = await User.create({ username: 'regularuser', password: '123456' });+ await Groups.join('Test', adminUid);+ await Groups.join('Test', regularUid);+ await helpers.copyFile(logoPath, imagePath);});it('should fail if user is not logged in or not owner', (done) => {