'use strict';

var should = require('should');
var rewire = require('rewire');
var dao = rewire('./bounce.dao');

function setupMonkMock(err, doc) {
	dao.__set__({
		db: {
			getCollection: function(collection) {
				collection.should.equal('bounces');
				return {
					find: function(search, options, next) {
						next(err, doc);
					}
				};
			}
		}
	});
}


describe('bounce.dao', function() {

	describe('findByToken()', function() {

		it('should return doc if single found', function() {

			setupMonkMock(null, ["one"]);

			dao.findByToken('some', function(err, doc) {
				should.not.exist(err);
				doc.should.equal("one");
			});

		});

		it('should return error if more then one match', function() {

			setupMonkMock(null, ["one", "two"]);

			dao.findByToken('some', function(err, doc) {
				should.exist(err);
				should.not.exist(doc);
			});

		});

		it('should return error if db error', function() {

			setupMonkMock(new Error("Some db error"), ["one", "two"]);

			dao.findByToken('some', function(err, doc) {
				should.exist(err);
				should.not.exist(doc);
			});

		});

	});

});
@@ -36,24 +36,56 @@
 ('should');%0A
+var assert = require('assert');%0A
 var rewire =
@@ -332,24 +332,88 @@
 ns, next) %7B%0A
+%09%09%09%09%09%09assert.deepEqual(search, %7B%0A%09%09%09%09%09%09%09token: %22some%22%0A%09%09%09%09%09%09%7D);%0A
 %09%09%09%09%09%09next(e

Enhance bounce.dao tests