aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mongo-factory/test/test.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-18 10:54:08 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-18 10:54:08 +0000
commita35da9f9ccc1124d9b6f4461c7216ffbb0285e2f (patch)
treed5b4b8548caae36a20e1258a8341dab4b3d522d2 /node_modules/mongo-factory/test/test.js
parent16bbc66ebafc6f1a55e47dbda3f3c0f658fe715c (diff)
parentc1ce89359a7b54ec97b54ce577e5534c180c5c4b (diff)
merged
Diffstat (limited to 'node_modules/mongo-factory/test/test.js')
-rw-r--r--node_modules/mongo-factory/test/test.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/node_modules/mongo-factory/test/test.js b/node_modules/mongo-factory/test/test.js
new file mode 100644
index 0000000..9ac91c3
--- /dev/null
+++ b/node_modules/mongo-factory/test/test.js
@@ -0,0 +1,94 @@
+var chai = require('chai');
+var expect = chai.expect;
+var mongo = require('mongodb');
+
+describe('mongoFactory', function() {
+ var mongoFactory;
+
+ beforeEach(function() {
+ mongoFactory = require('../');
+ });
+
+ it('can be required without blowing up', function(done) {
+ var mongoFactory = require('../');
+ expect(mongoFactory).to.exist;
+ done();
+ });
+
+ describe('getConnection()', function() {
+ describe('with no parameters', function() {
+ it('should fulfill the promise', function(done) {
+ var conn = mongoFactory.getConnection();
+ expect(conn).to.be.fulfilled;
+ done();
+ });
+
+ it('should reject the promise', function(done) {
+ var conn = mongoFactory.getConnection();
+ expect(conn).to.be.rejected;
+ done();
+ });
+ });
+
+ describe('with a null parameter', function() {
+ it('should reject the promise', function(done) {
+ var conn = mongoFactory.getConnection(null);
+ expect(conn).to.be.rejected;
+ done();
+ });
+ });
+
+ describe('with a valid mongo string parameter', function() {
+ describe('needing to create the pool the first time', function() {
+ it('should return a fulfilled promise', function(done) {
+ var conn = mongoFactory.getConnection('mongodb://localhost:27017').then(function(db) {
+ expect(conn).to.be.fulfilled;
+ expect(conn).to.not.be.rejected;
+ done();
+ });
+ });
+ });
+
+ describe('after a pool is already instantiated', function() {
+ it('should return a fulfilled promise', function(done) {
+ var conn1 = mongoFactory.getConnection('mongodb://localhost:27017').then(function() {
+ var conn = mongoFactory.getConnection('mongodb://localhost:27017').then(function() {
+ expect(conn).to.be.fulfilled;
+ expect(conn).to.not.be.rejected;
+ done();
+ });
+ });
+ });
+ });
+ });
+ });
+
+ describe('ObjectID', function() {
+ it('should return mongo\'s ObjectID method', function() {
+ var oid = mongoFactory.ObjectID;
+ expect(oid).to.be.a.function;
+ });
+
+ it('should allow you to create a new ObjectID', function() {
+ var oid = new mongoFactory.ObjectID;
+ expect(oid.toHexString().length).to.equal(24);
+ });
+
+ it('should allow you to compare ObjectIDs', function() {
+ var oid1 = new mongoFactory.ObjectID;
+ var oid2 = new mongoFactory.ObjectID(oid1.id);
+ var oid3 = new mongoFactory.ObjectID;
+ expect(oid1.equals(oid2));
+ expect(!oid1.equals(oid3));
+ });
+
+ it('should allow you to create a new ObjectID with a specific timestamp', function() {
+ // Get a timestamp in seconds
+ var timestamp = Math.floor(new Date().getTime()/1000);
+ // Create a date with the timestamp
+ var timestampDate = new Date(timestamp*1000);
+ var oid = new mongoFactory.ObjectID(timestamp);
+ expect(oid.getTimestamp().toString()).to.equal(timestampDate.toString());
+ });
+ });
+});