forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sadd.spec.js
62 lines (52 loc) · 2.27 KB
/
sadd.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sadd' method", function () {
helper.allTests(function (ip, args) {
describe('using ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once('ready', function () {
client.flushdb(done);
});
});
it('allows a single value to be added to the set', function (done) {
client.SADD('set0', 'member0', helper.isNumber(1));
client.smembers('set0', function (err, res) {
assert.ok(~res.indexOf('member0'));
return done(err);
});
});
it('does not add the same value to the set twice', function (done) {
client.sadd('set0', 'member0', helper.isNumber(1));
client.SADD('set0', 'member0', helper.isNumber(0, done));
});
it('allows multiple values to be added to the set', function (done) {
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 3);
assert.ok(~res.indexOf('member0'));
assert.ok(~res.indexOf('member1'));
assert.ok(~res.indexOf('member2'));
return done(err);
});
});
it('allows multiple values to be added to the set with a different syntax', function (done) {
client.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 3);
assert.ok(~res.indexOf('member0'));
assert.ok(~res.indexOf('member1'));
assert.ok(~res.indexOf('member2'));
return done(err);
});
});
afterEach(function () {
client.end(true);
});
});
});
});