/
hset.spec.js
85 lines (69 loc) · 3.06 KB
/
hset.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'hset' method", function () {
helper.allTests(function (ip, args) {
describe('using ' + ip, function () {
var client;
var hash = 'test hash';
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once('ready', function () {
client.flushdb(done);
});
});
it('allows a value to be set in a hash', function (done) {
var field = Buffer.from('0123456789');
var value = Buffer.from('abcdefghij');
client.hset(hash, field, value, helper.isNumber(1));
client.HGET(hash, field, helper.isString(value.toString(), done));
});
it('handles an empty value', function (done) {
var field = Buffer.from('0123456789');
var value = Buffer.alloc(0);
client.HSET(hash, field, value, helper.isNumber(1));
client.HGET([hash, field], helper.isString('', done));
});
it('handles empty key and value', function (done) {
var field = Buffer.alloc(0);
var value = Buffer.alloc(0);
client.HSET([hash, field, value], function (err, res) {
assert.strictEqual(res, 1);
client.HSET(hash, field, value, helper.isNumber(0, done));
});
});
it('errors if someone passed a array either as field or as value', function (done) {
var hash = 'test hash';
var field = 'array';
var value = ['array contents'];
try {
client.HMSET(hash, field, value);
} catch (error) {
assert(/node_redis: The HMSET command contains a invalid argument type./.test(error.message));
done();
}
});
it('does not error when a buffer and date are set as values on the same hash', function (done) {
var hash = 'test hash';
var field1 = 'buffer';
var value1 = Buffer.from('abcdefghij');
var field2 = 'date';
var value2 = new Date();
client.HMSET(hash, field1, value1, field2, value2, helper.isString('OK', done));
});
it('does not error when a buffer and date are set as fields on the same hash', function (done) {
var hash = 'test hash';
var value1 = 'buffer';
var field1 = Buffer.from('abcdefghij');
var value2 = 'date';
var field2 = new Date();
client.HMSET(hash, field1, value1, field2, value2, helper.isString('OK', done));
});
afterEach(function () {
client.end(true);
});
});
});
});