
var test = require('tape');

var nconf = require('nconf');

nconf.argv().env('_');

nconf.file({file: 'config/server.json'});

var db = require('../server/boot/db.js')(nconf, true);

test('Create and find simple user', function (t) {
    t.plan(3);
    // Clear DB
    db.models.User.remove();
    var user = new db.models.User();
    user.email = 'johndoe@example.com';
    user.save(function (err) {
        t.equal(null, err, 'Not error saving');
        db.models.User.findOne({ email: 'johndoe@example.com' }, function (err, user) {
            t.equal(null, err, 'Not error querying');
            t.equal(user.email, 'johndoe@example.com', 'Email matches');
        });
    });
});

test('User entity should have email', function (t) {
    t.plan(2);
    var user = new db.models.User();
    user.save(function (err) {
        t.ok(err, 'Inserting User without e-mail gives an error');
        t.equal(err.name, 'ValidationError', 'Error is a validation error');
    });
});

// We need this so the test exists, otherwise it stays running
test('disconnect', function (t) {
    t.plan(1);
    db.disconnect();
    t.pass('Disconnected');
});

@@ -125,17 +125,8 @@
 );%0A%0A
-var db = 
 requ
@@ -164,20 +164,46 @@
 nf, true
-);%0A%0A
+, function (__err, db) %7B%0A%0A    
 test('Cr
@@ -253,23 +253,31 @@
     
+   
+ 
 t.plan(
-3
+4
 );%0A    
+  
+  
 // C
@@ -284,24 +284,28 @@
 lear DB%0A    
+   
+ 
 db.models.Us
@@ -314,19 +314,113 @@
 .remove(
-);%0A
+function (err) %7B%0A            t.equal(err, null, 'No error removing collection');%0A        %7D);%0A    
     var 
@@ -440,32 +440,36 @@
 .models.User();%0A
+    
     user.email =
@@ -492,24 +492,28 @@
 e.com';%0A    
+ 
+   
 user.save(fu
@@ -531,32 +531,36 @@
 ) %7B%0A        
+    
 t.equal(
 null, err, '
@@ -543,39 +543,38 @@
     t.equal(
+err, 
 null,
- err,
  'No
-t
  error savin
@@ -578,32 +578,36 @@
 ving');%0A        
+ 
+   
 db.models.User.f
@@ -614,17 +614,16 @@
 indOne(%7B
- 
 email: '
@@ -642,17 +642,16 @@
 ple.com'
- 
 %7D, funct
@@ -680,24 +680,28 @@
         
+    
 t.equal(
 null, er
@@ -696,23 +696,22 @@
 ual(
+err, 
 null,
- err,
  'No
-t
  err
@@ -721,24 +721,28 @@
 querying');%0A
+    
             
@@ -810,24 +810,28 @@
         
+    
 %7D);%0A    
 %7D);%0A%7D);%0A
@@ -822,25 +822,37 @@
 %7D);%0A    
+  
+  
 %7D);%0A
+    
 %7D);%0A%0A
+    
 test('Us
@@ -888,32 +888,36 @@
  function (t) %7B%0A
+    
     t.plan(2);%0A 
@@ -915,16 +915,21 @@
 lan(2);%0A
+%0A    
     var 
@@ -957,24 +957,28 @@
 User();%0A    
+ 
+   
 user.save(fu
@@ -984,32 +984,36 @@
 unction (err) %7B%0A
+    
         t.ok(err
@@ -1063,32 +1063,36 @@
 rror');%0A        
+   
+ 
 t.equal(err.name
@@ -1152,80 +1152,29 @@
     
-%7D);%0A%7D);%0A%0A// We need this so the test exists, otherwise it stays running%0A
+    %7D);%0A    %7D);%0A%0A    
 test
@@ -1203,24 +1203,28 @@
 n (t) %7B%0A    
+ 
+   
 t.plan(1);%0A 
@@ -1222,16 +1222,20 @@
 lan(1);%0A
+    
     db.d
@@ -1251,16 +1251,20 @@
 ();%0A    
+   
+ 
 t.pass('
@@ -1279,12 +1279,20 @@
 cted');%0A
+    %7D);%0A
 %7D);%0A

Fix tests