<commit_before>'use strict';

// modules dependencies
var mongoat = require('../../index');

var _this;

// test insert method
describe('Insert', function () {
  // connect to db before all tests
  beforeAll(function (done) {
    _this = this;

    mongoat.MongoClient.connect('mongodb://localhost:27017/mongoatTest')
    .then(function (db) {
      db.dropDatabase();
      _this.testDb = db;
      _this.testCol = db.collection('Person-insert');

      done();
    });
  });

  // close db after all tests
  afterAll(function (done) {
    _this.testCol.find()
    .toArray()
    .then(function (mongoArray) {
      expect(mongoArray.length).toBe(2);

      for (var i = 0; i < mongoArray.length; ++i) {
        expect(mongoArray[i].firstName).toBe('Yacine');
        expect(mongoArray[i].lastName).toBe('KHATAl');
        expect(mongoArray[i].age).toBe(25);
        if (i > 0) {
          expect(mongoArray[i].email).toBe('<EMAIL>');
          expect(mongoArray[i].company).toBe('Dial Once');
        }
      }

      _this.testDb.dropDatabase();
      _this.testDb.close();
      done();
    });
  });

  // test insert without hooks
  it('should insert new document to Person collection',
  function (done) {
    _this.testCol.insert({
      firstName: 'Yacine',
      lastName: 'KHATAl',
      age: 25
    }).then(function (mongObject) {
      expect(typeof mongObject).toBe('object');
      expect(typeof mongObject.result).toBe('object');
      expect(mongObject.result.ok).toBe(1);
      expect(mongObject.result.n).toBe(1);
      done();
    });
  });

  // test with multiple before and after insert hooks
  it('should insert new document to Person collection and handle before and after insert hooks',
  function (done) {
    // add before insert hooks
    _this.testCol.before('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      object.email = '<EMAIL>';
      return object;
    });

    _this.testCol.before('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      expect(object.email).toBe('<EMAIL>');
      object.company = 'Dial Once';
      return object;
    });

    // add after insert hooks
    _this.testCol.after('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      expect(object.email).toBe('<EMAIL>');
      expect(object.company).toBe('Dial Once');
      return object;
    });

    _this.testCol.after('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      expect(object.email).toBe('<EMAIL>');
      expect(object.company).toBe('Dial Once');
      return object;
    });

    _this.testCol.insert({
      firstName: 'Yacine',
      lastName: 'KHATAl',
      age: 25
    }).then(function (mongObject) {
      expect(typeof mongObject).toBe('object');
      expect(typeof mongObject.result).toBe('object');
      expect(mongObject.result.ok).toBe(1);
      expect(mongObject.result.n).toBe(1);
      
      done();
    });
  });
});
<commit_msg>Add spec for datetime feature<commit_after>'use strict';

// modules dependencies
var mongoat = require('../../index');

var _this;

// test insert method
describe('Insert', function () {
  // connect to db before all tests
  beforeAll(function (done) {
    _this = this;

    mongoat.MongoClient.connect('mongodb://localhost:27017/mongoatTest')
    .then(function (db) {
      db.dropDatabase();
      _this.testDb = db;
      _this.testCol = db.collection('Person-insert');
      _this.testCol.datetime(true);

      done();
    });
  });

  // close db after all tests
  afterAll(function (done) {
    _this.testCol.find()
    .toArray()
    .then(function (mongoArray) {
      expect(mongoArray.length).toBe(2);

      for (var i = 0; i < mongoArray.length; ++i) {
        expect(mongoArray[i].firstName).toBe('Yacine');
        expect(mongoArray[i].lastName).toBe('KHATAl');
        expect(mongoArray[i].age).toBe(25);
        expect(mongoArray[i].createdAt).toBeDefined();
        if (i > 0) {
          expect(mongoArray[i].email).toBe('<EMAIL>');
          expect(mongoArray[i].company).toBe('Dial Once');
        }
      }

      _this.testDb.dropDatabase();
      _this.testDb.close();
      done();
    });
  });

  // test insert without hooks
  it('should insert new document to Person collection',
  function (done) {
    _this.testCol.insert({
      firstName: 'Yacine',
      lastName: 'KHATAl',
      age: 25
    }).then(function (mongObject) {
      expect(typeof mongObject).toBe('object');
      expect(typeof mongObject.result).toBe('object');
      expect(mongObject.result.ok).toBe(1);
      expect(mongObject.result.n).toBe(1);
      done();
    });
  });

  // test with multiple before and after insert hooks
  it('should insert new document to Person collection and handle before and after insert hooks',
  function (done) {
    // add before insert hooks
    _this.testCol.before('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      object.email = '<EMAIL>';
      return object;
    });

    _this.testCol.before('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      expect(object.email).toBe('<EMAIL>');
      object.company = 'Dial Once';
      return object;
    });

    // add after insert hooks
    _this.testCol.after('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      expect(object.email).toBe('<EMAIL>');
      expect(object.company).toBe('Dial Once');
      return object;
    });

    _this.testCol.after('insert', function (object) {
      expect(object.firstName).toBe('Yacine');
      expect(object.lastName).toBe('KHATAl');
      expect(object.age).toBe(25);
      expect(object.email).toBe('<EMAIL>');
      expect(object.company).toBe('Dial Once');
      return object;
    });

    _this.testCol.insert({
      firstName: 'Yacine',
      lastName: 'KHATAl',
      age: 25
    }).then(function (mongObject) {
      expect(typeof mongObject).toBe('object');
      expect(typeof mongObject.result).toBe('object');
      expect(mongObject.result.ok).toBe(1);
      expect(mongObject.result.n).toBe(1);
      
      done();
    });
  });
});

{'fraction_non_alphanumeric': 0.16792985584782286, 'fraction_numerical': 0.007727745578837866, 'mean_word_length': 2.8834391229082517, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '1645950', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2093, 'n_words': 376}