UNPKG

1.43 kBJavaScriptView Raw
1var t = require('../test-lib/test.js');
2var assert = require('assert');
3
4var apos;
5
6describe('Db', function() {
7
8 this.timeout(t.timeout);
9
10 it('should exist on the apos object', function(done) {
11 apos = require('../index.js')({
12 root: module,
13 shortName: 'test',
14
15 afterInit: function(callback) {
16 assert(apos.db);
17 // Verify a normal, boring connection to localhost without the db option worked
18 return apos.docs.db.findOne().then(function(doc) {
19 assert(doc);
20 return done();
21 }).catch(function(err) {
22 console.error(err);
23 assert(false);
24 });
25 }
26 });
27 });
28
29 it('should be able to launch a second instance reusing the connection', function(done) {
30 var apos2 = require('../index.js')({
31 root: module,
32 shortName: 'test2',
33 modules: {
34 'apostrophe-express': {
35 port: 7777
36 },
37 'apostrophe-db': {
38 db: apos.db,
39 uri: 'mongodb://this-will-not-work-unless-db-successfully-overrides-it/fail'
40 }
41 },
42 afterInit: function(callback) {
43 return apos.docs.db.findOne().then(function(doc) {
44 assert(doc);
45 return t.destroy(apos2, function() {
46 return t.destroy(apos, done);
47 });
48 }).catch(function(err) {
49 console.error(err);
50 assert(false);
51 });
52 }
53 });
54 });
55});