Skip to content

Commit

Permalink
Merge branch 'feature-collections' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe M. Silva committed Feb 7, 2020
2 parents 9456249 + 308d926 commit 3f0165a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class DB {
}

this.MongoClient = mongoClient || MongoClient;

this.conn = this.MongoClient.connect(this.url, {
useUnifiedTopology: true,
});

return this;
}

Expand Down Expand Up @@ -67,10 +72,7 @@ class DB {
};

get connection() {
return this.MongoClient.connect(this.url, {
useUnifiedTopology: true,
useNewUrlParser: true,
}).then(result => result.db(this.config.database));
return this.conn.then(result => result.db(this.config.database));
}

get validConfig() {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"test": "tests"
},
"scripts": {
"test": "npm run test:unit-coverage && npm run test:integration",
"test": "npm run test:coverage && npm run test:integration",
"test:unit": "mocha ./test/lib/**.test.js --exit",
"test:integration": "mocha ./test/integration.test.js --exit",
"test:unit-coverage": "nyc --reporter=lcov mocha ./test/lib/**.test.js"
"test:coverage": "npx nyc@latest --reporter=lcov --reporter=text-summary npm run test:unit"
},
"repository": {
"type": "git",
Expand Down
28 changes: 28 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,33 @@ describe('Test integration with mongo db', () => {
done();
});
});

it('expect create data in two collections', (done) => {
const col = db.collection('new_collection');

col('insert', { name: 'verify' })
.then((ops) => {

expect(ops.result).to.be.a('object');
expect(ops.result).to.have.property('ok');
expect(ops.result.ok).to.be.equal(1);

done();
});

const col2 = db.collection('new_collection2');

col2('insert', { name: 'verify' })
.then((ops) => {

expect(ops.result).to.be.a('object');
expect(ops.result).to.have.property('ok');
expect(ops.result.ok).to.be.equal(1);

done();
});
});


});
});

0 comments on commit 3f0165a

Please sign in to comment.