Node.js based forum software built for the modern web
fixed tests, and added getSortedSetUnion method to redis db, added test for new redis method
Julian Lam6e597a9cdb19
diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.jsindex 13dad80013..4c6ab89c8a 100644--- a/src/database/redis/sorted.js+++ b/src/database/redis/sorted.js@@ -73,4 +73,33 @@ module.exports = function(redisClient, module) {multi.exec(callback);};++ module.getSortedSetUnion = function(sets, start, stop, callback) {+ // start and stop optional+ if (typeof start === 'function') {+ callback = start;+ start = 0;+ stop = -1;+ } else if (typeof stop === 'function') {+ callback = stop;+ stop = -1;+ }++ var multi = redisClient.multi();++ // zunionstore prep+ sets.unshift(sets.length);+ sets.unshift('temp');++ multi.zunionstore.apply(multi, sets);+ multi.zrange('temp', start, stop);+ multi.del('temp');+ multi.exec(function(err, results) {+ if (!err && typeof callback === 'function') {+ callback(null, results[1]);+ } else if (err) {+ callback(err);+ }+ });+ }};\ No newline at end of filediff --git a/src/routes/debug.js b/src/routes/debug.jsindex 2534576d20..ed988db2ee 100644--- a/src/routes/debug.js+++ b/src/routes/debug.js@@ -54,9 +54,10 @@ module.exports = function(app, middleware, controllers) {});app.get('/test', function(req, res) {- var privileges = require('../privileges');- privileges.topics.get(1299, 1, function(err, result) {- res.json(result);+ var db = require('../database');+ db.getSortedSetUnion(['uid:1:posts', 'uid:3:posts'], function(err, pids) {+ console.log(err);+ res.json(pids);});});});diff --git a/src/topics/tags.js b/src/topics/tags.jsindex 492723f750..6cee4f76b5 100644--- a/src/topics/tags.js+++ b/src/topics/tags.js@@ -23,6 +23,8 @@ module.exports = function(Topics) {next(err);});}, callback);+ } else {+ callback();}};diff --git a/tests/database.js b/tests/database.jsindex cdd5041407..6176d26c9a 100644--- a/tests/database.js+++ b/tests/database.js@@ -20,7 +20,7 @@ describe('Test database', function() {}function set(callback) {- db.set('testingStr', 'opppa gangastayla', function(err, data) {+ db.set('testingStr', 'oppa gangnam style', function(err, data) {callback(err, {'set': data});});}@@ -324,6 +324,12 @@ describe('Test database', function() {});}+ function getSortedSetUnion(callback) {+ db.getSortedSetUnion(['users:joindate', 'users:derp', 'users:postcount'], function(err, data) {+ callback(err, {'sortedSetUnion': data});+ });+ }+var sortedSetTasks = [sortedSetAdd,sortedSetAdd,@@ -337,7 +343,8 @@ describe('Test database', function() {sortedSetCount,sortedSetScore,sortedSetsScore,- getSortedSetRevRangeByScore+ getSortedSetRevRangeByScore,+ getSortedSetUnion];async.series(sortedSetTasks, function(err, results) {diff --git a/tests/groups.js b/tests/groups.jsindex 96d98eeaeb..d3c4bb5d85 100644--- a/tests/groups.js+++ b/tests/groups.js@@ -14,7 +14,7 @@ describe('Groups', function() {},function(next) {// Create a new user- User.create({+ User.create({username: 'testuser',email: '[email protected]'}, done);diff --git a/tests/topics.js b/tests/topics.jsindex 5433ab3746..8d94bbd59a 100644--- a/tests/topics.js+++ b/tests/topics.js@@ -3,31 +3,42 @@var assert = require('assert'),db = require('../mocks/databasemock'),topics = require('../src/topics'),- categories = require('../src/categories');+ categories = require('../src/categories'),+ User = require('../src/user');describe('Topic\'s', function() {var topic,categoryObj;before(function(done) {+ var userData = {+ username: 'John Smith',+ password: 'swordfish',+ email: '[email protected]',+ callback: undefined+ };- categories.create({- name: 'Test Category',- description: 'Test category created by testing script',- icon: 'fa-check',- blockclass: 'category-blue',- order: '5'- }, function(err, category) {- categoryObj = category;+ User.create({username: userData.username, password: userData.password, email: userData.email}, function(err, uid) {+ categories.create({+ name: 'Test Category',+ description: 'Test category created by testing script',+ icon: 'fa-check',+ blockclass: 'category-blue',+ order: '5'+ }, function(err, category) {+ categoryObj = category;- topic = {- userId: 1,- categoryId: categoryObj.cid,- title: 'Test Topic Title',- content: 'The content of test topic'- };- done();+ topic = {+ userId: uid,+ categoryId: categoryObj.cid,+ title: 'Test Topic Title',+ content: 'The content of test topic'+ };+ done();+ });});++});describe('.post', function() {