forked from howdyai/botkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage_test.js
71 lines (61 loc) · 2.43 KB
/
storage_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
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
/*
Tests for storage modules.
This file currently test simple_storage.js, redis_storage, and firebase_storage.
If you build a new storage module,
you must add it to this test file before your PR will be considered.
How to add it to this test file:
Add the following to the bottom of this file:
// Test <your_storage_module>
<your_storage_module> = require('./<your_storage_module>.js')(<appropriate config object for your storage module>);
check(<your_storage_module>.users);
check(<your_storage_module>.channels);
check(<your_storage_module>.teams);
*/
var test = require('unit.js');
testObj0 = {id: 'TEST0', foo: 'bar0'};
testObj1 = {id: 'TEST1', foo: 'bar1'};
var testStorageMethod = function(storageMethod) {
storageMethod.save(testObj0, function(err) {
test.assert(!err);
storageMethod.save(testObj1, function(err) {
test.assert(!err);
storageMethod.get(testObj0.id, function(err, data) {
test.assert(!err);
console.log(data);
test.assert(data.foo === testObj0.foo);
});
storageMethod.get('shouldnt-be-here', function(err, data) {
test.assert(err.displayName === 'NotFound');
test.assert(!data);
});
storageMethod.all(function(err, data) {
test.assert(!err);
console.log(data);
test.assert(
data[0].foo === testObj0.foo && data[1].foo === testObj1.foo ||
data[0].foo === testObj1.foo && data[1].foo === testObj0.foo
);
});
});
});
};
console.log('If no asserts failed then the test has passed!');
// Test simple_storage
var simple_storage = require('./simple_storage.js')();
testStorageMethod(simple_storage.users);
testStorageMethod(simple_storage.channels);
testStorageMethod(simple_storage.teams);
// Test redis_storage
var redis_storage = require('./redis_storage.js')({
url: 'redis://redistogo:[email protected]:11895/'
});
testStorageMethod(redis_storage.users);
testStorageMethod(redis_storage.channels);
testStorageMethod(redis_storage.teams);
// Test firebase_storage
var firebase_storage = require('./firebase_storage.js')({
firebase_uri: 'https://botkit-example.firebaseio.com'
});
testStorageMethod(firebase_storage.users);
testStorageMethod(firebase_storage.channels);
testStorageMethod(firebase_storage.teams);