<commit_before>var vows = require('vows');
var assert = require('assert');
var dbmeta = require('db-meta');
var dataType = require('../../lib/data_type');
var driver = require('../../lib/driver');

var config = require('../db.config.json').mongodb;

global.migrationTable = 'migrations';

var dbName = config.database;
driver.connect(config, function(err, db) {
  assert.isNull(err);
  vows.describe('mongodb')
  .addBatch({
    'createCollection': {
      topic: function() {
        db.createCollection('event', this.callback);
      },

      teardown: function() {
        db.dropCollection('event', this.callback);
      },

      'has table metadata': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'containing the event table': function(err, tables) {
          assert.equal(tables.length, 2);	// Should be 2 b/c of the system collection
        }
      }
    }
  })
  .addBatch({
    'dropCollection': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }

          db.dropCollection('event', this.callback);
        }.bind(this));
      },

      'has table metadata': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'containing no tables': function(err, tables) {
          assert.isNotNull(tables);
          assert.equal(tables.length, 1);	// Should be 1 b/c of the system collection
        }
      }
    }
  })
  .addBatch({
    'renameCollection': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }

          db.renameCollection('event', 'functions', this.callback);
        }.bind(this));
      },

      teardown: function() {
        db.dropCollection('functions', this.callback);
      },


      'has table metadata': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'containing the functions table': function(err, tables) {
          assert.isNotNull(tables);
          assert.equal(tables.length, 2);	// Should be 2 b/c of the system collection
          assert.equal(tables[1].collectionName, 'functions');
        }
      }
    }
  })
  .addBatch({
    'addIndex': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }

          db.addIndex('event', 'event_title', 'title', false, this.callback);
        }.bind(this));
      },

      teardown: function() {
        db.dropCollection('event', this.callback);
      },

      'preserves case': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'of the functions original table': function(err, tables) {
          assert.isNotNull(tables);
          assert.equal(tables.length, 2);	// Should be 2 b/c of the system collection
          assert.equal(tables[1].collectionName, 'event');
        }
      },

      'has resulting index metadata': {
        topic: function() {
          db._getIndexes('event', this.callback);
        },

        'with additional index': function(err, indexes) {
          assert.isDefined(indexes);
          assert.isNotNull(indexes);
          assert.include(indexes, 'event_title');
        }
      }
    }
  })
  .addBatch({
    'insert': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }
          db.insert('event', [{id: 2, title: 'title'}], function(err) { console.log(err); this.callback(err);}.bind(this));
        }.bind(this));
      },<commit_msg>remove debug messages<commit_after>var vows = require('vows');
var assert = require('assert');
var dbmeta = require('db-meta');
var dataType = require('../../lib/data_type');
var driver = require('../../lib/driver');

var config = require('../db.config.json').mongodb;

global.migrationTable = 'migrations';

var dbName = config.database;
driver.connect(config, function(err, db) {
  assert.isNull(err);
  vows.describe('mongodb')
  .addBatch({
    'createCollection': {
      topic: function() {
        db.createCollection('event', this.callback);
      },

      teardown: function() {
        db.dropCollection('event', this.callback);
      },

      'has table metadata': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'containing the event table': function(err, tables) {
          assert.equal(tables.length, 2);	// Should be 2 b/c of the system collection
        }
      }
    }
  })
  .addBatch({
    'dropCollection': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }

          db.dropCollection('event', this.callback);
        }.bind(this));
      },

      'has table metadata': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'containing no tables': function(err, tables) {
          assert.isNotNull(tables);
          assert.equal(tables.length, 1);	// Should be 1 b/c of the system collection
        }
      }
    }
  })
  .addBatch({
    'renameCollection': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }

          db.renameCollection('event', 'functions', this.callback);
        }.bind(this));
      },

      teardown: function() {
        db.dropCollection('functions', this.callback);
      },


      'has table metadata': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'containing the functions table': function(err, tables) {
          assert.isNotNull(tables);
          assert.equal(tables.length, 2);	// Should be 2 b/c of the system collection
          assert.equal(tables[1].collectionName, 'functions');
        }
      }
    }
  })
  .addBatch({
    'addIndex': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }

          db.addIndex('event', 'event_title', 'title', false, this.callback);
        }.bind(this));
      },

      teardown: function() {
        db.dropCollection('event', this.callback);
      },

      'preserves case': {
        topic: function() {
          db._getCollectionNames(this.callback);
        },

        'of the functions original table': function(err, tables) {
          assert.isNotNull(tables);
          assert.equal(tables.length, 2);	// Should be 2 b/c of the system collection
          assert.equal(tables[1].collectionName, 'event');
        }
      },

      'has resulting index metadata': {
        topic: function() {
          db._getIndexes('event', this.callback);
        },

        'with additional index': function(err, indexes) {
          assert.isDefined(indexes);
          assert.isNotNull(indexes);
          assert.include(indexes, 'event_title');
        }
      }
    }
  })
  .addBatch({
    'insert': {
      topic: function() {
        db.createCollection('event', function(err, collection) {
          if(err) {
            return this.callback(err);
          }
          db.insert('event', [{id: 2, title: 'title'}], this.callback);
        }.bind(this));
      },
{'fraction_non_alphanumeric': 0.1499736425935688, 'fraction_numerical': 0.0028993147074327886, 'mean_word_length': 2.0824532900081234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7458488', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2124, 'n_words': 438}