forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo-storage.test.js
55 lines (40 loc) · 1.41 KB
/
mongo-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
'use strict';
var should = require('should');
var assert = require('assert');
describe('mongo storage', function () {
var env = require('../env')();
before(function (done) {
delete env.api_secret;
done();
});
it('The module should be OK.', function (done) {
should.exist(require('../lib/storage/mongo-storage'));
done();
});
it('After initializing the storage class it should re-use the open connection', function (done) {
var store = require('../lib/storage/mongo-storage');
store(env, function (err1, db1) {
should.not.exist(err1);
store(env, function (err2, db2) {
should.not.exist(err2);
assert(db1.db, db2.db, 'Check if the handlers are the same.');
done();
});
});
});
it('When no connection-string is given the storage-class should throw an error.', function (done) {
delete env.storageURI;
should.not.exist(env.storageURI);
(function () {
return require('../lib/storage/mongo-storage')(env, false, true);
}).should.throw('MongoDB connection string is missing. Please set MONGO_CONNECTION environment variable');
done();
});
it('An invalid connection-string should throw an error.', function (done) {
env.storageURI = 'This is not a MongoDB connection-string';
(function () {
return require('../lib/storage/mongo-storage')(env, false, true);
}).should.throw(Error);
done();
});
});