From b171f3072b0606964e81d5703d42802e3ea4f831 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Fri, 26 May 2017 17:16:59 -0600
Subject: [PATCH] Fix many "duplicate key" errors
- Reset defaults after every test
- Remove individual `after(db.emptydb)` calls
- Fix async.every in groups test
- Update plugin list in socket tests
---
test/authentication.js | 4 ----
test/blacklist.js | 4 ----
test/build.js | 7 +------
test/categories.js | 7 +------
test/controllers-admin.js | 4 ----
test/controllers.js | 5 +----
test/database/hash.js | 5 -----
test/database/keys.js | 5 -----
test/database/list.js | 5 -----
test/database/sets.js | 5 -----
test/database/sorted.js | 4 ----
test/feeds.js | 4 ----
test/flags.js | 4 ----
test/groups.js | 10 +++-------
test/logger.js | 4 ----
test/messaging.js | 4 ----
test/meta.js | 5 -----
test/mocks/databasemock.js | 13 +++++++++----
test/notifications.js | 5 -----
test/posts.js | 5 -----
test/rewards.js | 5 -----
test/search.js | 4 ----
test/socket.io.js | 5 +----
test/topics.js | 4 ----
test/uploads.js | 5 -----
test/user.js | 5 -----
26 files changed, 16 insertions(+), 121 deletions(-)
diff --git a/test/authentication.js b/test/authentication.js
index 4b8bcc209e..b0dd89186c 100644
--- a/test/authentication.js
+++ b/test/authentication.js
@@ -427,9 +427,5 @@ describe('authentication', function () {
},
], done);
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/blacklist.js b/test/blacklist.js
index 72f5e1e813..5668597b13 100644
--- a/test/blacklist.js
+++ b/test/blacklist.js
@@ -72,8 +72,4 @@ describe('blacklist', function () {
assert(blacklist.test('1.1.1.1'));
done();
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/build.js b/test/build.js
index a05331f463..1287165a17 100644
--- a/test/build.js
+++ b/test/build.js
@@ -124,9 +124,8 @@ describe('Build', function (done) {
var build = require('../src/meta/build');
before(function (done) {
- async.series([
+ async.parallel([
async.apply(rimraf, path.join(__dirname, '../build/public')),
- db.setupMockDefaults,
async.apply(db.activatePlugin, 'nodebb-plugin-markdown'),
], done);
});
@@ -232,8 +231,4 @@ describe('Build', function (done) {
done();
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/categories.js b/test/categories.js
index 8ef059d8cb..9c481fc317 100644
--- a/test/categories.js
+++ b/test/categories.js
@@ -20,7 +20,7 @@ describe('Categories', function () {
before(function (done) {
groups.resetCache();
- async.parallel({
+ async.series({
posterUid: function (next) {
User.create({ username: 'poster' }, next);
},
@@ -680,9 +680,4 @@ describe('Categories', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/controllers-admin.js b/test/controllers-admin.js
index df5d3d58d8..0d2549ba0f 100644
--- a/test/controllers-admin.js
+++ b/test/controllers-admin.js
@@ -553,8 +553,4 @@ describe('Admin Controllers', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/controllers.js b/test/controllers.js
index 4ae64e612d..8b01551773 100644
--- a/test/controllers.js
+++ b/test/controllers.js
@@ -1765,9 +1765,6 @@ describe('Controllers', function () {
after(function (done) {
var analytics = require('../src/analytics');
- analytics.writeData(function (err) {
- assert.ifError(err);
- db.emptydb(done);
- });
+ analytics.writeData(done);
});
});
diff --git a/test/database/hash.js b/test/database/hash.js
index cffa761229..c1b12aaed7 100644
--- a/test/database/hash.js
+++ b/test/database/hash.js
@@ -408,9 +408,4 @@ describe('Hash methods', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/database/keys.js b/test/database/keys.js
index afbf3c947c..a18eee181e 100644
--- a/test/database/keys.js
+++ b/test/database/keys.js
@@ -170,9 +170,4 @@ describe('Key methods', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/database/list.js b/test/database/list.js
index 7d00df3e8d..063a316b2d 100644
--- a/test/database/list.js
+++ b/test/database/list.js
@@ -200,9 +200,4 @@ describe('List methods', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/database/sets.js b/test/database/sets.js
index a3e79df81c..eeafe0ba57 100644
--- a/test/database/sets.js
+++ b/test/database/sets.js
@@ -226,9 +226,4 @@ describe('Set methods', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/database/sorted.js b/test/database/sorted.js
index 9e0178d4ed..1cf46204df 100644
--- a/test/database/sorted.js
+++ b/test/database/sorted.js
@@ -902,8 +902,4 @@ describe('Sorted Set methods', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/feeds.js b/test/feeds.js
index 4fd0bbd90e..e8e3f8dfa4 100644
--- a/test/feeds.js
+++ b/test/feeds.js
@@ -113,8 +113,4 @@ describe('feeds', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/flags.js b/test/flags.js
index 5d45b8afef..274927e382 100644
--- a/test/flags.js
+++ b/test/flags.js
@@ -564,8 +564,4 @@ describe('Flags', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/groups.js b/test/groups.js
index d329c5292f..ceba296c61 100644
--- a/test/groups.js
+++ b/test/groups.js
@@ -436,10 +436,10 @@ describe('Groups', function () {
var groups = ['Test', 'Hidden'];
async.every(groups, function (group, next) {
Groups.isMember(testUid, group, function (err, isMember) {
- assert.ifError(err);
- next(!isMember);
+ next(err, !isMember);
});
- }, function (result) {
+ }, function (err, result) {
+ assert.ifError(err);
assert(result);
done();
@@ -1189,8 +1189,4 @@ describe('Groups', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/logger.js b/test/logger.js
index 8bfeb9052f..8b455a87ca 100644
--- a/test/logger.js
+++ b/test/logger.js
@@ -28,8 +28,4 @@ describe('logger', function () {
done();
}, 500);
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/messaging.js b/test/messaging.js
index 5a9b0ac4a3..d6426812fe 100644
--- a/test/messaging.js
+++ b/test/messaging.js
@@ -610,8 +610,4 @@ describe('Messaging Library', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/meta.js b/test/meta.js
index a92f6c74f6..9338580274 100644
--- a/test/meta.js
+++ b/test/meta.js
@@ -275,9 +275,4 @@ describe('meta', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/mocks/databasemock.js b/test/mocks/databasemock.js
index d9ce5432c9..7b1e5cb604 100644
--- a/test/mocks/databasemock.js
+++ b/test/mocks/databasemock.js
@@ -116,7 +116,7 @@ before(function (done) {
nconf.set('theme_config', path.join(nconf.get('themes_path'), 'nodebb-theme-persona', 'theme.json'));
nconf.set('bcrypt_rounds', 1);
- next();
+ meta.dependencies.check(next);
},
function (next) {
var webserver = require('../../src/webserver');
@@ -129,6 +129,14 @@ before(function (done) {
webserver.listen(next);
},
], done);
+
+ // Iterate over all of the test suites/contexts
+ this.test.parent.suites.forEach(function (suite) {
+ // Attach an afterAll listener that resets the defaults
+ suite.afterAll(function (done) {
+ setupMockDefaults(done);
+ });
+ });
});
function setupMockDefaults(callback) {
@@ -148,9 +156,6 @@ function setupMockDefaults(callback) {
function (next) {
meta.configs.init(next);
},
- function (next) {
- meta.dependencies.check(next);
- },
function (next) {
meta.config.postDelay = 0;
meta.config.initialPostDelay = 0;
diff --git a/test/notifications.js b/test/notifications.js
index d2585e4029..314e901822 100644
--- a/test/notifications.js
+++ b/test/notifications.js
@@ -475,9 +475,4 @@ describe('Notifications', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/posts.js b/test/posts.js
index 74172d808d..b3a5b38056 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -740,9 +740,4 @@ describe('Post\'s', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/rewards.js b/test/rewards.js
index 965df4770f..d707eb5f4c 100644
--- a/test/rewards.js
+++ b/test/rewards.js
@@ -73,9 +73,4 @@ describe('rewards', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/search.js b/test/search.js
index a18f6b3b41..119f833a80 100644
--- a/test/search.js
+++ b/test/search.js
@@ -165,8 +165,4 @@ describe('Search', function () {
done();
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/socket.io.js b/test/socket.io.js
index 38e64fbd25..52d8ebc1fe 100644
--- a/test/socket.io.js
+++ b/test/socket.io.js
@@ -485,6 +485,7 @@ describe('socket.io', function () {
var data = [
{ name: 'nodebb-theme-persona', order: 0 },
{ name: 'nodebb-plugin-dbsearch', order: 1 },
+ { name: 'nodebb-plugin-soundpack-default', order: 2 },
{ ignoreme: 'wrong data' },
];
socketAdmin.plugins.orderActivePlugins({ uid: adminUid }, data, function (err) {
@@ -585,9 +586,5 @@ describe('socket.io', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/topics.js b/test/topics.js
index 2d3d7a4cf6..da3d148e70 100644
--- a/test/topics.js
+++ b/test/topics.js
@@ -1643,8 +1643,4 @@ describe('Topic\'s', function () {
});
});
});
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/uploads.js b/test/uploads.js
index 5acc480e4c..ca8e3b1bea 100644
--- a/test/uploads.js
+++ b/test/uploads.js
@@ -256,9 +256,4 @@ describe('Upload Controllers', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});
diff --git a/test/user.js b/test/user.js
index 495caf17fb..4678c2282f 100644
--- a/test/user.js
+++ b/test/user.js
@@ -1467,9 +1467,4 @@ describe('User', function () {
});
});
});
-
-
- after(function (done) {
- db.emptydb(done);
- });
});