Node.js based forum software built for the modern web
sortedSetRange tests
barisusakli00541b2bc850
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.jsindex 2031155b78..c61e748a14 100644--- a/src/database/mongo/sorted.js+++ b/src/database/mongo/sorted.js@@ -100,6 +100,22 @@ module.exports = function(db, module) {});};+ module.getSortedSetRange = function(key, start, stop, callback) {+ getSortedSetRange(key, start, stop, 1, false, callback);+ };++ module.getSortedSetRevRange = function(key, start, stop, callback) {+ getSortedSetRange(key, start, stop, -1, false, callback);+ };++ module.getSortedSetRangeWithScores = function(key, start, stop, callback) {+ getSortedSetRange(key, start, stop, 1, true, callback);+ };++ module.getSortedSetRevRangeWithScores = function(key, start, stop, callback) {+ getSortedSetRange(key, start, stop, -1, true, callback);+ };+function getSortedSetRange(key, start, stop, sort, withScores, callback) {if (!key) {return callback();@@ -128,22 +144,6 @@ module.exports = function(db, module) {});}- module.getSortedSetRange = function(key, start, stop, callback) {- getSortedSetRange(key, start, stop, 1, false, callback);- };-- module.getSortedSetRevRange = function(key, start, stop, callback) {- getSortedSetRange(key, start, stop, -1, false, callback);- };-- module.getSortedSetRangeWithScores = function(key, start, stop, callback) {- getSortedSetRange(key, start, stop, 1, true, callback);- };-- module.getSortedSetRevRangeWithScores = function(key, start, stop, callback) {- getSortedSetRange(key, start, stop, -1, true, callback);- };-module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {getSortedSetRangeByScore(key, start, count, min, max, 1, false, callback);};diff --git a/tests/database/sorted.js b/tests/database/sorted.jsindex d5a532ccb2..0a7f11db5c 100644--- a/tests/database/sorted.js+++ b/tests/database/sorted.js@@ -7,7 +7,6 @@ var async = require('async'),describe('Sorted Set methods', function() {describe('sortedSetAdd()', function() {-it('should add an element to a sorted set', function(done) {db.sortedSetAdd('sorted1', 1, 'value1', function(err) {assert.equal(err, null);@@ -35,6 +34,67 @@ describe('Sorted Set methods', function() {});});+ describe('getSortedSetRange()', function() {+ it('should return the lowest scored element', function(done) {+ db.getSortedSetRange('sorted2', 0, 0, function(err, value) {+ assert.equal(err, null);+ assert.equal(arguments.length, 2);+ assert.equal(value, 'value1');+ done();+ });+ });++ it('should return elements sorted by score lowest to highest', function(done) {+ db.getSortedSetRange('sorted2', 0, -1, function(err, values) {+ assert.equal(err, null);+ assert.equal(arguments.length, 2);+ assert.deepEqual(values, ['value1', 'value2', 'value3']);+ done();+ });+ });+ });++ describe('getSortedSetRevRange()', function() {+ it('should return the highest scored element', function(done) {+ db.getSortedSetRevRange('sorted2', 0, 0, function(err, value) {+ assert.equal(err, null);+ assert.equal(arguments.length, 2);+ assert.equal(value, 'value3');+ done();+ });+ });++ it('should return elements sorted by score highest to lowest', function(done) {+ db.getSortedSetRevRange('sorted2', 0, -1, function(err, values) {+ assert.equal(err, null);+ assert.equal(arguments.length, 2);+ assert.deepEqual(values, ['value3', 'value2', 'value1']);+ done();+ });+ });+ });++ describe('getSortedSetRangeWithScores()', function() {+ it('should return array of elements sorted by score lowest to highest with scores', function(done) {+ db.getSortedSetRangeWithScores('sorted2', 0, -1, function(err, values) {+ assert.equal(err, null);+ assert.equal(arguments.length, 2);+ assert.deepEqual(values, [{value: 'value1', score: 1}, {value: 'value2', score: 2}, {value: 'value3', score: 3}]);+ done();+ });+ });+ });++ describe('getSortedSetRevRangeWithScores()', function() {+ it('should return array of elements sorted by score highest to lowest with scores', function(done) {+ db.getSortedSetRevRangeWithScores('sorted2', 0, -1, function(err, values) {+ assert.equal(err, null);+ assert.equal(arguments.length, 2);+ assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}, {value: 'value1', score: 1}]);+ done();+ });+ });+ });after(function() {