Skip to content

Node.js based forum software built for the modern web

sorted set tests

barisusakli0ff37f9e0e36
diff --git a/tests/database.js b/tests/database.js
index 6238f9fa13..9118823d00 100644
--- a/tests/database.js
+++ b/tests/database.js
@@ -14,103 +14,6 @@ describe('Test database', function() {
require('./database/list');
require('./database/sets');
require('./database/hash');
+ require('./database/sorted');
-
- it('should not throw err', function(done) {
- function sortedSetAdd(callback) {
- db.sortedSetAdd('sortedSet3', 12, 5, function(err) {
- callback(err);
- });
- }
-
- function sortedSetRemove(callback) {
- db.sortedSetRemove('sortedSet3', 12, function(err, data) {
- callback(err);
- });
- }
-
- function getSortedSetRange(callback) {
- db.getSortedSetRange('sortedSet3', 0, -1, function(err, data) {
- callback(err, {'getSortedSetRange': data});
- });
- }
-
- function getSortedSetRevRange(callback) {
- db.getSortedSetRevRange('sortedSet3', 0, -1, function(err, data) {
- callback(err, {'getSortedSetRevRange': data});
- });
- }
-
- function getSortedSetRevRangeByScore(callback) {
- db.getSortedSetRevRangeByScore('sortedSet3', 0, 10, Infinity, 100, function(err, data) {
- callback(err, {'getSortedSetRevRangeByScore': data});
- });
- }
-
- function sortedSetCount(callback) {
- db.sortedSetCount('sortedSet3', -Infinity, Infinity, function(err, data) {
- callback(err, {'sortedSetCount': data});
- });
- }
-
- function sortedSetScore(callback) {
- db.sortedSetScore('users:joindate', 1, function(err, data) {
- callback(err, {'sortedSetScore': data});
- });
- }
-
- function sortedSetsScore(callback) {
- db.sortedSetsScore(['users:joindate', 'users:derp', 'users:postcount'], 1, function(err, data) {
- callback(err, {'sortedSetsScore': data});
- });
- }
-
- function isSortedSetMember(callback) {
- db.isSortedSetMember('sortedSet3', 5, function(err, data) {
- callback(err, {'sortedSetMember': data});
- });
- }
-
- function getSortedSetUnion(callback) {
- db.getSortedSetUnion(['users:joindate', 'users:derp', 'users:postcount'], 0, -1, function(err, data) {
- callback(err, {'sortedSetUnion': data});
- });
- }
-
- function getSortedSetRevUnion(callback) {
- db.getSortedSetRevUnion(['users:joindate', 'users:derp', 'users:postcount'], 0, -1, function(err, data) {
- callback(err, {'sortedSetUnion': data});
- });
- }
-
- var sortedSetTasks = [
- sortedSetAdd,
- sortedSetAdd,
- isSortedSetMember,
- getSortedSetRange,
- sortedSetAdd,
- getSortedSetRange,
- getSortedSetRevRange,
- sortedSetRemove,
- getSortedSetRange,
- sortedSetCount,
- sortedSetScore,
- sortedSetsScore,
- getSortedSetRevRangeByScore,
- getSortedSetUnion,
- getSortedSetRevUnion
- ];
-
- async.series(sortedSetTasks, function(err, results) {
- assert.equal(err, null, 'error in sorted set methods');
- assert.ok(results);
-
- done();
- });
-
- });
-
- after(function() {
- db.flushdb();
- });
});
diff --git a/tests/database/sorted.js b/tests/database/sorted.js
new file mode 100644
index 0000000000..d5a532ccb2
--- /dev/null
+++ b/tests/database/sorted.js
@@ -0,0 +1,43 @@
+'use strict';
+
+var async = require('async'),
+ assert = require('assert'),
+ db = require('../mocks/databasemock');
+
+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);
+ assert.equal(arguments.length, 1);
+ done();
+ });
+ });
+
+ it('should add two elements to a sorted set', function(done) {
+ db.sortedSetAdd('sorted2', [1, 2], ['value1', 'value2'], function(err) {
+ assert.equal(err, null);
+ assert.equal(arguments.length, 1);
+ done();
+ });
+ });
+ });
+
+ describe('sortedSetsAdd()', function() {
+ it('should add an element to two sorted sets', function(done) {
+ db.sortedSetsAdd(['sorted1, sorted2'], 3, 'value3', function(err) {
+ assert.equal(err, null);
+ assert.equal(arguments.length, 1);
+ done();
+ });
+ });
+ });
+
+
+
+ after(function() {
+ db.flushdb();
+ });
+});