'use strict';

var sinon = require('sinon');
var chai = require('chai');
var expect = chai.expect;

var mongodb = require('mongodb');
var Driver = require('../');

chai.config.includeStack = true;

describe('mongodb driver', function() {
  var driver, model;

  before(function(done) {
    model = {
      bucket: 'mock'
    };

    mongodb.MongoClient.connect('mongodb://localhost:27017/osmos', {}, function(err, db) {
      if(err) {
        done(err);
      } else {
        driver = new Driver(db);

        done();
      }
    });
  });

  describe('generic', function() {
    it('should be a constructor', function() {
      expect(Driver).to.be.a('function');
    });

    it('should wrap mongo object without driver', function() {
      expect(driver).to.be.an('object').to.have.property('database');
    });
  });

  describe('create', function() {
    it('should be able to create an object', function(done) {
      driver
        .create()
        .then(function(doc) {
          expect(doc)
            .to.be.an('object')
            .to.be.empty;

          done();
        });
    });

    it('should be able to find an empty object', function(done) {
      driver
        .get(model, 'test')
        .then(function(doc) {
          expect(doc)
            .to.not.exist;
          done();
        });
    });
  });
});

@@ -1323,13 +1323,1509 @@
 );%0A  %7D);
+%0A%0A  describe('when getting data from mongodb', function() %7B%0A%0A    describe('when an error occurred', function() %7B%0A%0A      it('should catch error', function(done) %7B%0A        sinon.stub(driver.database, 'collection', function(bucket) %7B%0A          return %7B%0A            findOne: function(arg, callback) %7B%0A              process.nextTick(function() %7B%0A                callback(new Error('fake'));%0A              %7D);%0A            %7D%0A          %7D;%0A        %7D);%0A%0A        driver.get(model, 'key').catch(function(err) %7B%0A          expect(err).to.exist;%0A          expect(err).to.have.property('message').to.be.equal('fake');%0A%0A          driver.database.collection.restore();%0A%0A          done();%0A        %7D);%0A      %7D);%0A%0A    %7D);%0A%0A    describe('when document is found', function() %7B%0A%0A      it('should be able to transform id to hexstring', function(done) %7B%0A%0A        sinon.stub(driver.database, 'collection', function(bucket) %7B%0A          return %7B%0A            findOne: function(spec, callback) %7B%0A              process.nextTick(function() %7B%0A                callback(null, %7B%0A                  _id: %7B%0A                    toHexString: function() %7B%0A                      return spec._id;%0A                    %7D%0A                  %7D%0A                %7D)%0A              %7D);%0A            %7D%0A          %7D;%0A        %7D);%0A%0A        driver.get(model, 'key').then(function(doc) %7B%0A%0A          expect(doc).to.have.property('_id').to.be.equal('key');%0A%0A          driver.database.collection.restore();%0A%0A          done();%0A        %7D);%0A%0A      %7D);%0A    %7D);%0A  %7D);
 %0A%7D);%0A

add scenarios for get