var assert = require("assert");
var helpers = require("./helpers");
var db;

describe('On spin up', function () {

  before(function(done){
    helpers.resetDb(function(err,res){
      db = res;
      done();
    });
  });
  it('returns a valid db interface', function () {
    assert(db && db.tables && db.queryFiles && db.connectionString);
  });
  it('loads non-public schema as namespace property', function() {
    assert(db.myschema, "No Schema loaded");
  });
  it('loads tables in db schema as properties of namespace', function() {
    assert(db.myschema.artists && db.myschema.albums, 'No tables loaded on schema');
  });
  it('loads up 10 tables with 2 in schema object in array property', function () {
    assert.equal(db.tables.length, 10);
  });

  // including one nested in a deeper folder... total of 4 now.
  it('loads up 7 queries', function () {
    assert.equal(db.queryFiles.length, 7);
  });
  it('loads up functions', function () {
    // newer versions of postgres include more than 20 functions
    assert.ok(db.functions.length >= 20);
  });
});

var syncLoaded;
var path = require("path");
var scriptsDir = path.join(__dirname, ".", "db");

describe('Synchronous Load', function () {

  it('loads the db synchronously and blocks execution until complete', function() {
    // no need to re-set the back-end; it wasn't changed by the previous 'suite' ...
    syncLoaded = require("../index").loadSync({connectionString: helpers.connectionString, scripts: scriptsDir});
    assert(syncLoaded && syncLoaded.tables && syncLoaded.queryFiles && syncLoaded.connectionString);
  });
  it('returns a valid db instance from sync load function', function () {
    assert(syncLoaded && syncLoaded.tables && syncLoaded.queryFiles && syncLoaded.connectionString);
  });
  it('loads non-public schema as namespace property', function () {
    assert(syncLoaded.myschema, "No Schema loaded");
  });
  it('loads tables in syncLoaded schema as properties of namespace', function() {
    assert(syncLoaded.myschema.artists && syncLoaded.myschema.albums, 'No tables loaded on schema');
  });
  it('loads up 10 tables with 2 in schema object in array property', function () {
    assert.equal(syncLoaded.tables.length, 10);
  });

  // including one nested in a deeper folder... total of 4 now.
  it('loads up 7 queries', function () {
    assert.equal(syncLoaded.queryFiles.length, 7);
  });
  it('loads up functions', function () {
    // newer versions of postgres include more than 20 functions
    assert.ok(syncLoaded.functions.length >= 20);
  });
});

@@ -804,33 +804,33 @@
 der... total of 
-4
+8
  now.%0A  it('load
@@ -826,33 +826,33 @@
 %0A  it('loads up 
-7
+8
  queries', funct
@@ -891,33 +891,33 @@
 ryFiles.length, 
-7
+8
 );%0A  %7D);%0A  it('l
@@ -2293,9 +2293,9 @@
  of 
-4
+8
  now
@@ -2311,17 +2311,17 @@
 oads up 
-7
+8
  queries
@@ -2388,9 +2388,9 @@
 th, 
-7
+8
 );%0A 

fix script load count