UNPKG

1.46 kBJavaScriptView Raw
1'use strict';
2
3var mongoose = require('mongoose');
4var Mockgoose = require('../built/mockgoose').Mockgoose;
5var expect = require('chai').expect;
6var mockgoose = new Mockgoose(mongoose);
7var CatSchema = new mongoose.Schema({name: String});
8var Cat1;
9var Cat2;
10
11// create connection to first database
12describe('bug 15', function() {
13
14 before("DB1 connection", function () {
15 return mockgoose.prepareStorage().then(function() {
16 return mongoose.createConnection("mongodb://barbaz", { useNewUrlParser: true });
17 }).then(function(db1) {
18 Cat1 = db1.model('Cat', CatSchema);
19 });
20 });
21
22 // create connection to second database
23 before("DB2 connection", function () {
24 return mockgoose.prepareStorage().then(function() {
25 return mongoose.createConnection("mongodb://foobar", { useNewUrlParser: true });
26 }).then(function (db2) {
27 Cat2 = db2.model('Cat', CatSchema);
28 });
29 });
30
31 it("should create a cat foo", function(done) {
32 Cat1.create({
33 name: "foo"
34 }, function(err) {
35 expect(err).not.to.be.ok;
36 done(err);
37 });
38 });
39
40 it("should find cat foo", function(done) {
41 Cat1.findOne({name: "foo"}, function(err) {
42 expect(err).not.to.be.ok;
43 done(err);
44 });
45 });
46
47 // remove collections from a temporary store
48 after("Drop db", function(done) {
49 // Here is when the error is trigged
50 mockgoose.helper.reset().then(function() {
51 done();
52 });
53 });
54});