mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
fixed tests, and added getSortedSetUnion method to redis db, added test for new redis method
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,6 +23,8 @@ module.exports = function(Topics) {
|
||||
next(err);
|
||||
});
|
||||
}, callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -3,14 +3,22 @@
|
||||
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: 'john@example.com',
|
||||
callback: undefined
|
||||
};
|
||||
|
||||
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',
|
||||
@@ -21,7 +29,7 @@ describe('Topic\'s', function() {
|
||||
categoryObj = category;
|
||||
|
||||
topic = {
|
||||
userId: 1,
|
||||
userId: uid,
|
||||
categoryId: categoryObj.cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic'
|
||||
@@ -30,6 +38,9 @@ describe('Topic\'s', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('.post', function() {
|
||||
|
||||
it('should create a new topic with proper parameters', function(done) {
|
||||
|
||||
Reference in New Issue
Block a user