<commit_before>var assert = require('assert');
var sinon = require('sinon');
var mongoose = require('mongoose');
require('sinon-as-promised');

require('../lib');

describe('sinon-mongoose', function () {

  var bookSchema = new mongoose.Schema({
    title: String
  });

  var Book = mongoose.model('Book', bookSchema);

  describe('should made Mongoose model methods chainables', function () {

    it('#find', function (done) {
      var BookMock = sinon.mock(Book);

      BookMock
        .expects('find').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      Book.find('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          BookMock.verify();
          BookMock.restore();
          assert.equal(result, 'RESULT');
          done();
        });
    });
  });

  describe('should made Mongoose document methods chainables', function () {

    it('#update', function (done) {
      var bookMock = sinon.mock(new Book({ title: 'Rayuela' }));

      bookMock
        .expects('update').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      bookMock.object.update('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          bookMock.verify();
          bookMock.restore();
          assert.equal(result, 'RESULT');
          done();
        });
    });
  });

  describe('using sinon sandbox', function () {
    var sandbox = sinon.sandbox.create();

    afterEach(function () {
      sandbox.verify();
      sandbox.restore();
    });

    it('should work mocking Model', function () {
      var BookMock = sandbox.mock(Book);

      BookMock
        .expects('find').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      Book.find('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          assert.equal(result, 'RESULT');
        });
    });

    it('should work mocking Document', function () {
      var bookMock = sandbox.mock(new Book({ title: 'Rayuela' }));

      bookMock
        .expects('update').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      bookMock.object.update('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          assert.equal(result, 'RESULT');
        });
    });
  });
});
<commit_msg>Added tests for lean and count methods<commit_after>var assert = require('assert');
var sinon = require('sinon');
var mongoose = require('mongoose');
require('sinon-as-promised');

require('../lib');

describe('sinon-mongoose', function () {

  var bookSchema = new mongoose.Schema({
    title: String
  });

  var Book = mongoose.model('Book', bookSchema);

  describe('should made Mongoose model methods chainables', function () {

    it('#find', function (done) {
      var BookMock = sinon.mock(Book);

      BookMock
        .expects('find').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      Book.find('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          BookMock.verify();
          BookMock.restore();
          assert.equal(result, 'RESULT');
          done();
        });
    });

    it('#lean', function (done) {
      var BookMock = sinon.mock(Book);

      BookMock
        .expects('find').withArgs('SOME_ARGUMENTS')
        .chain('lean')
        .chain('exec')
        .resolves('RESULT');

      Book.find('SOME_ARGUMENTS')
        .lean()
        .exec()
        .then(function (result) {
          BookMock.verify();
          BookMock.restore();
          assert.equal(result, 'RESULT');
          done();
        });
    });

    it('#count', function (done) {
      var BookMock = sinon.mock(Book);

      BookMock
        .expects('find').withArgs('SOME_ARGUMENTS')
        .chain('count')
        .chain('exec')
        .resolves('RESULT');

      Book.find('SOME_ARGUMENTS')
        .count()
        .exec()
        .then(function (result) {
          BookMock.verify();
          BookMock.restore();
          assert.equal(result, 'RESULT');
          done();
        });
    });
  });

  describe('should made Mongoose document methods chainables', function () {

    it('#update', function (done) {
      var bookMock = sinon.mock(new Book({ title: 'Rayuela' }));

      bookMock
        .expects('update').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      bookMock.object.update('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          bookMock.verify();
          bookMock.restore();
          assert.equal(result, 'RESULT');
          done();
        });
    });
  });

  describe('using sinon sandbox', function () {
    var sandbox = sinon.sandbox.create();

    afterEach(function () {
      sandbox.verify();
      sandbox.restore();
    });

    it('should work mocking Model', function () {
      var BookMock = sandbox.mock(Book);

      BookMock
        .expects('find').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      Book.find('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          assert.equal(result, 'RESULT');
        });
    });

    it('should work mocking Document', function () {
      var bookMock = sandbox.mock(new Book({ title: 'Rayuela' }));

      bookMock
        .expects('update').withArgs('SOME_ARGUMENTS')
        .chain('exec')
        .resolves('RESULT');

      bookMock.object.update('SOME_ARGUMENTS')
        .exec()
        .then(function (result) {
          assert.equal(result, 'RESULT');
        });
    });
  });
});

{'fraction_non_alphanumeric': 0.1676796567751162, 'fraction_numerical': 0.0, 'mean_word_length': 2.2359745517640253, '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': '6762648', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1661, 'n_words': 302}