fixed tests, and added getSortedSetUnion method to redis db, added test for new redis method

v1.18.x
Julian Lam 11 years ago
parent 840a56006c
commit 6e597a9cdb

@ -73,4 +73,33 @@ module.exports = function(redisClient, module) {
multi.exec(callback); 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);
}
});
}
}; };

@ -54,9 +54,10 @@ module.exports = function(app, middleware, controllers) {
}); });
app.get('/test', function(req, res) { app.get('/test', function(req, res) {
var privileges = require('../privileges'); var db = require('../database');
privileges.topics.get(1299, 1, function(err, result) { db.getSortedSetUnion(['uid:1:posts', 'uid:3:posts'], function(err, pids) {
res.json(result); console.log(err);
res.json(pids);
}); });
}); });
}); });

@ -23,6 +23,8 @@ module.exports = function(Topics) {
next(err); next(err);
}); });
}, callback); }, callback);
} else {
callback();
} }
}; };

@ -20,7 +20,7 @@ describe('Test database', function() {
} }
function set(callback) { function set(callback) {
db.set('testingStr', 'opppa gangastayla', function(err, data) { db.set('testingStr', 'oppa gangnam style', function(err, data) {
callback(err, {'set': 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 = [ var sortedSetTasks = [
sortedSetAdd, sortedSetAdd,
sortedSetAdd, sortedSetAdd,
@ -337,7 +343,8 @@ describe('Test database', function() {
sortedSetCount, sortedSetCount,
sortedSetScore, sortedSetScore,
sortedSetsScore, sortedSetsScore,
getSortedSetRevRangeByScore getSortedSetRevRangeByScore,
getSortedSetUnion
]; ];
async.series(sortedSetTasks, function(err, results) { async.series(sortedSetTasks, function(err, results) {

@ -14,7 +14,7 @@ describe('Groups', function() {
}, },
function(next) { function(next) {
// Create a new user // Create a new user
User.create({ User.create({
username: 'testuser', username: 'testuser',
email: 'b@c.com' email: 'b@c.com'
}, done); }, done);

@ -3,31 +3,42 @@
var assert = require('assert'), var assert = require('assert'),
db = require('../mocks/databasemock'), db = require('../mocks/databasemock'),
topics = require('../src/topics'), topics = require('../src/topics'),
categories = require('../src/categories'); categories = require('../src/categories'),
User = require('../src/user');
describe('Topic\'s', function() { describe('Topic\'s', function() {
var topic, var topic,
categoryObj; categoryObj;
before(function(done) { before(function(done) {
var userData = {
username: 'John Smith',
password: 'swordfish',
email: 'john@example.com',
callback: undefined
};
categories.create({ User.create({username: userData.username, password: userData.password, email: userData.email}, function(err, uid) {
name: 'Test Category', categories.create({
description: 'Test category created by testing script', name: 'Test Category',
icon: 'fa-check', description: 'Test category created by testing script',
blockclass: 'category-blue', icon: 'fa-check',
order: '5' blockclass: 'category-blue',
}, function(err, category) { order: '5'
categoryObj = category; }, function(err, category) {
categoryObj = category;
topic = { topic = {
userId: 1, userId: uid,
categoryId: categoryObj.cid, categoryId: categoryObj.cid,
title: 'Test Topic Title', title: 'Test Topic Title',
content: 'The content of test topic' content: 'The content of test topic'
}; };
done(); done();
});
}); });
}); });
describe('.post', function() { describe('.post', function() {

Loading…
Cancel
Save