-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
38 lines (30 loc) · 1.14 KB
/
test.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
const test = require('tape');
const jsonappy = require('./');
const redis = require('redis');
const provider = redis.createClient({ return_buffers: true, prefix: 'jsonappy:test:' });
test('encode and decode', t => {
t.plan(2);
jsonappy({ foo: 'bar' }).then(buffer => {
t.equal(Buffer.isBuffer(buffer), true, 'encode');
jsonappy(buffer).then(data => t.equal(data.foo, 'bar', 'decode'));
});
});
test('do not decode invalid values', { timeout: 3000 }, t => {
t.plan(3);
jsonappy(null).then(data => t.equal(data, null, 'null'));
jsonappy(false).then(data => t.equal(data, false, 'false'));
jsonappy(undefined).then(data => t.equal(data, undefined, 'undefined'));
});
test('provider set and get', { timeout: 3000 }, t => {
const expected = { foo: 'bar' };
t.plan(1);
jsonappy(provider).set('foobar', expected).then(() => {
jsonappy(provider).get('foobar').then(data => t.equal(data.foo, 'bar'));
provider.del('foobar');
});
});
test('send provider empty values', { timeout: 3000 }, t => {
t.plan(1);
jsonappy(provider).get('ajsipdjaisopdja').then(data => t.equal(data, null));
});
test.onFinish(() => process.exit(0));