'use strict';

var test = require('tap').test;
var expressMongoDb = require('./');

test('should connect pass error on fail', function (t) {
	var middleware = expressMongoDb('mongodb://localhost:31337');

	middleware({}, {}, function (err) {
		t.ok(err);
		t.end();
	});
});

test('should connect to mongodb', function (t) {
	var middleware = expressMongoDb('mongodb://localhost:27017');
	var req = {};

	middleware(req, {}, function (err) {
		t.error(err);
		t.ok(req.db);
		req.db.close(true, t.end);
	});
});

test('should connect to mongodb with custom property', function (t) {
	var middleware = expressMongoDb('mongodb://localhost:27017', {
		property: 'myDb'
	});
	var req = {};

	middleware(req, {}, function (err) {
		t.error(err);
		t.ok(req.myDb);
		req.myDb.close(true, t.end);
	});
});

test('should return same connection for multiple requests', function (t) {
	var middleware = expressMongoDb('mongodb://localhost:27017', {
		property: 'myDb'
	});
	var req = {};

	var _db;

	middleware(req, {}, function (err) {
		t.error(err);
		t.ok(req.myDb);
		_db = req.myDb;

		middleware(req, {}, function (err) {
			t.error(err);
			t.equal(_db, req.myDb);
			req.myDb.close(true, t.end);
		});
	});
});

@@ -83,30 +83,166 @@
 %0A%0Atest('
-should connect
+throws on invalid uri', function (t) %7B%0A%09t.throws(function () %7B%0A%09%09expressMongoDb();%0A%09%7D, /Expected uri to be a string/);%0A%09t.end();%0A%7D);%0A%0Atest('middleware
  pass er
@@ -380,24 +380,78 @@
 %09t.ok(err);%0A
+%0A%09%09middleware(%7B%7D, %7B%7D, function (err) %7B%0A%09%09%09t.ok(err);%0A%09
 %09%09t.end();%0A%09
@@ -449,16 +449,22 @@
 .end();%0A
+%09%09%7D);%0A
 %09%7D);%0A%7D);
@@ -467,38 +467,49 @@
 %0A%7D);%0A%0Atest('
-should
+middleware stores
  connect
  to mongodb'
@@ -488,32 +488,35 @@
 e stores connect
+ion
  to mongodb', fu
@@ -726,38 +726,39 @@
 st('
-should connect to mongodb with
+middleware stores connection in
  cus
@@ -1014,21 +1014,15 @@
 st('
-should 
 return
+s
  sam

Throw more tests in it