-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
63 lines (51 loc) · 1.66 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
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
'use strict';
const mongo = require('.');
const assert = require('assert');
const mongodb = require('mongodb');
before(done => mongo.on('ready', done));
describe('mongo', () => {
it('returns Mongo wrapper class', () => {
assert(mongo instanceof mongo.MongoWrapper);
assert(mongo.db instanceof mongodb.Db);
assert(mongo.api.users instanceof mongodb.Collection);
[
'arrangementer',
'bilder',
'grupper',
'lister',
'områder',
'steder',
'turer',
].forEach((type) => {
assert(mongo[type] instanceof mongodb.Collection);
});
});
it('is connected to the database', (done) => {
mongo.db.stats((err, stats) => {
assert.ifError(err);
assert.equal(stats.ok, 1);
done();
});
});
it('connects via MONGO_URI environment variable', done => {
process.env.MONGO_URI = 'mongodb://mongo:27017/test';
delete require.cache[require.resolve('.')];
require('.').on('ready', function readyCb() { // eslint-disable-line global-require
// assert(this instanceof mongo.MongoWrapper);
assert(this.db instanceof mongodb.Db);
done();
});
delete process.env.MONGO_URI;
});
it('connects via MONGO_PORT_27017_TCP_* environment variables', done => {
process.env.MONGO_PORT_27017_TCP_ADDR = 'mongo';
process.env.MONGO_PORT_27017_TCP_PORT = '27017';
delete require.cache[require.resolve('.')];
require('.').on('ready', function readyCb() { // eslint-disable-line global-require
assert(this.db instanceof mongodb.Db);
done();
});
delete process.env.MONGO_PORT_27017_TCP_ADDR;
delete process.env.MONGO_PORT_27017_TCP_PORT;
});
});