-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.js
107 lines (88 loc) · 3.17 KB
/
tests.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var should = require('should'),
kvs = require('./index');
describe('keyvalue-xyz', function() {
describe('token generation', function() {
it('should succeed', function(done) {
kvs.createToken('mykey', function(error, response) {
should.not.exist(error);
should.exist(response);
response.should.be.an.instanceof(String).and.have.lengthOf(8);
done();
});
});
});
describe('storing values', function() {
const key = 'test-storing';
var token = null;
beforeEach(function(done) {
kvs.createToken(key, function(error, response) {
should.exist(response);
token = response;
done();
});
});
it('should succeed', function(done) {
kvs.setValueForKey(token, key, 'test', function(error) {
should.not.exist(error);
done();
});
});
it('should succeed with JSON', function (done) {
kvs.setJSONForKey(token, key, { 'hello': 'world' }, function(error) {
should.not.exist(error);
done();
});
});
});
describe('fetching values', function() {
const key = 'test-fetching';
var token = null;
beforeEach(function(done) {
kvs.createToken(key, function(error, response) {
should.exist(response);
token = response;
done();
});
});
it('should fetch empty data', function(done) {
kvs.getValueForKey(token, key, function(error, response) {
should.not.exist(error);
should.not.exist(response);
done();
});
});
it('should fetch empty JSON', function(done) {
kvs.getJSONForKey(token, key, function(error, response) {
should.not.exist(error);
should.exist(response);
response.should.be.empty;
done();
});
});
it('should fetch previously set value', function(done) {
let value = 'abcdef';
kvs.setValueForKey(token, key, value, function(error) {
should.not.exist(error);
kvs.getValueForKey(token, key, function(error, response) {
should.not.exist(error);
should.exist(response);
response.should.be.equal(value);
done();
});
});
});
it('should fetch previously set JSON value', function() {
let value = { 'foo': 'bar' };
kvs.setJSONForKey(token, key, value, function(error) {
should.not.exist(error);
kvs.getJSONForKey(token, key, function(error, response) {
should.not.exist(error);
should.exist(response);
response.should.have.property('foo');
response.foo.should.be.equal('bar');
done();
});
});
});
});
});