<commit_before>import {expect} from 'chai';
import Database from '../lib/Database';
import Cursor from '../lib/Cursor';
import {ObjectId} from '../index.js';

require('bluebird').longStackTraces();


describe('Collection', function () {
  let db;
  let collection;

  beforeEach(async function () {
    db = new Database('pmongo_test');
    await db.dropDatabase();
    collection = db.collection('docs');
  });

  describe('aggregate', function () {
    it('supports $group', async function () {
      await collection.insert([
        { name: 'Squirtle', type: 'water' },
        { name: 'Starmie', type: 'water' },
        { name: 'Charmander', type: 'fire' },
        { name: 'Lapras', type: 'water' }
      ]);

      let result = await collection.aggregate({$group: {_id: '$type'}});
      expect(result).to.deep.have.members([{_id: 'water' }, {_id: 'fire'}]);
    });
  });

  describe('aggregateCursor', function () {
    it('supports $group', async function () {
      await collection.insert([
        { name: 'Squirtle', type: 'water' },
        { name: 'Starmie', type: 'water' },
        { name: 'Charmander', type: 'fire' },
        { name: 'Lapras', type: 'water' }
      ]);

      let cursor = collection.aggregateCursor({$group: {_id: '$type'}});
      expect(cursor).to.be.an.instanceof(Cursor);
      let result = await cursor.toArray();
      expect(result).to.deep.have.members([{_id: 'water' }, {_id: 'fire'}]);
    });
  });

  describe('count', function() {
    it('returns the number of items in the collection', async function() {
      await collection.insert([{number: 1}, {number: 2}, {number: 3}]);
      let result = await collection.count();
      expect(result).to.equal(3);
    });
  });

  describe('createIndex', function () {
    it('adds an index to the system.indexes collection', async function () {
      await collection.createIndex({number: 1});
      let count = await db.collection('system.indexes').count({'key.number': 1});
      expect(count).to.equal(1);
    });
  });

  describe('distinct', function () {
    it('returns the distinct values', async function () {
      await collection.insert([{number: 1}, {number: 1}, {number: 2}, {number: 3}]);
      let result = await collection.distinct('number');
      expect(result).to.have.members([1,2,3]);
    });
  });

  describe('drop', function () {<commit_msg>test: full text index options<commit_after>import {expect} from 'chai';
import Database from '../lib/Database';
import Cursor from '../lib/Cursor';
import {ObjectId} from '../index.js';

require('bluebird').longStackTraces();


describe('Collection', function () {
  let db;
  let collection;

  beforeEach(async function () {
    db = new Database('pmongo_test');
    await db.dropDatabase();
    collection = db.collection('docs');
  });

  describe('aggregate', function () {
    it('supports $group', async function () {
      await collection.insert([
        { name: 'Squirtle', type: 'water' },
        { name: 'Starmie', type: 'water' },
        { name: 'Charmander', type: 'fire' },
        { name: 'Lapras', type: 'water' }
      ]);

      let result = await collection.aggregate({$group: {_id: '$type'}});
      expect(result).to.deep.have.members([{_id: 'water' }, {_id: 'fire'}]);
    });
  });

  describe('aggregateCursor', function () {
    it('supports $group', async function () {
      await collection.insert([
        { name: 'Squirtle', type: 'water' },
        { name: 'Starmie', type: 'water' },
        { name: 'Charmander', type: 'fire' },
        { name: 'Lapras', type: 'water' }
      ]);

      let cursor = collection.aggregateCursor({$group: {_id: '$type'}});
      expect(cursor).to.be.an.instanceof(Cursor);
      let result = await cursor.toArray();
      expect(result).to.deep.have.members([{_id: 'water' }, {_id: 'fire'}]);
    });
  });

  describe('count', function() {
    it('returns the number of items in the collection', async function() {
      await collection.insert([{number: 1}, {number: 2}, {number: 3}]);
      let result = await collection.count();
      expect(result).to.equal(3);
    });
  });

  describe('createIndex', function () {
    it('adds an index to the system.indexes collection', async function () {
      await collection.createIndex({number: 1});
      let count = await db.collection('system.indexes').count({'key.number': 1});
      expect(count).to.equal(1);
    });

    it('adds an index to the system.indexes collection with the specified full text options', async function () {
      await collection.createIndex({name: 'text', tags: 'text'}, {default_language: 'english', weights: {name: 10, tags: 5}, name: 'testFtIndex'});
      let index = await db.collection('system.indexes').findOne({'name': 'testFtIndex'});
      expect(index.weights).to.deep.equal({name: 10, tags: 5});
    });
  });

  describe('distinct', function () {
    it('returns the distinct values', async function () {
      await collection.insert([{number: 1}, {number: 1}, {number: 2}, {number: 3}]);
      let result = await collection.distinct('number');
      expect(result).to.have.members([1,2,3]);
    });
  });

  describe('drop', function () {
{'fraction_non_alphanumeric': 0.19244917715392063, 'fraction_numerical': 0.006582768635043562, 'mean_word_length': 3.330259849119866, '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': '4075590', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1584, 'n_words': 386}