Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
officert committed Feb 6, 2016
1 parent 75a32ad commit d4e4813
Showing 1 changed file with 170 additions and 0 deletions.
170 changes: 170 additions & 0 deletions tests/integration/entities/database/addCollection-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
'use strict';

require('tests/integration/before-all');

const should = require('should');
const sinon = require('sinon');
require('sinon-as-promised');

let Connection;
let sandbox;
let errors;

before(() => {
sandbox = sinon.sandbox.create();

Connection = require('lib/entities/connection');

errors = require('lib/errors');
});

afterEach(() => {
sandbox.restore();
});

describe('entities', () => {
describe('database', () => {
describe('addConnection', () => {
describe('when no options are passed', () => {
let connection;
let database;
let options = null;

before(done => {
connection = new Connection({
name: 'FOobar Connection',
host: 'foobar.com',
port: 2000,
databaseName: 'Foobar'
});

database = connection.databases[0];

return done(null);
});

it('should reject with an error', next => {
database.addCollection(options)
.catch(err => {
should.exist(err);

err.message.should.equal('database - addCollection() - options is required');

return next(null);
});
});
});

describe('when options.name is not passed', () => {
let connection;
let database;
let options = {
name: null
};

before(done => {
connection = new Connection({
name: 'FOobar Connection',
host: 'foobar.com',
port: 2000,
databaseName: 'Foobar'
});

database = connection.databases[0];

return done(null);
});

it('should reject with an error', next => {
database.addCollection(options)
.catch(err => {
should.exist(err);

err.message.should.equal('database - addCollection() - options.name is required');

return next(null);
});
});
});

describe('when database is not yet connected', () => {
let connection;
let database;
let options = {
name: 'Foobar'
};

before(done => {
connection = new Connection({
name: 'FOobar Connection',
host: 'foobar.com',
port: 2000,
databaseName: 'Foobar'
});

database = connection.databases[0];

return done(null);
});

it('should reject with an error', next => {
database.addCollection(options)
.catch(err => {
should.exist(err);

err.message.should.equal('database - addCollection() - database is not connected yet');

return next(null);
});
});
});

// describe('when database is connected but options.name is not unique', () => {
// let connection;
// let database;
// let collectionName = 'Collection 1';
// let options = {
// name: collectionName
// };
//
// before(done => {
// connection = new Connection({
// name: 'FOobar Connection',
// host: 'localhost',
// port: 27017,
// databaseName: 'Foobar'
// });
//
// database = connection.databases[0];
//
// database.open()
// .then(() => {
// database.addCollection({
// name: collectionName
// })
// .then(() => {
// return done(null);
// })
// .catch(err => {
// return done(err);
// });
// })
// .catch(err => {
// return done(err);
// });
// });
//
// it('should reject with an error', next => {
// database.addCollection(options)
// .catch(err => {
// should.exist(err);
//
// err.message.should.equal('database - addCollection() - options.name is required');
//
// return next(null);
// });
// });
// });
});
});
});

0 comments on commit d4e4813

Please sign in to comment.