<commit_before>/* global describe, it, before, beforeEach, after, afterEach */

import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import through from 'through2';
import concat from 'concat-stream';
import ldapjs from 'ldapjs';
import settings from './settings.example.js';
import TestLDAPServer from './ldapServer';
import mockData from './mockData';
import SimpleLDAP from '../src/';

const { expect } = chai;
chai.use(chaiAsPromised);

describe('LDAP', () => {
  let ldap; // the ldap client
  const server = new TestLDAPServer();

  // start the LDAP server for testing
  before((done) => {
    server
      .start()
      .then(done)
      .catch(done);
  });

  after((done) => {
    server
      .stop()
      .then(done)
      .catch(done);
  });

  // create a new connection to test LDAP server
  beforeEach((done) => {
    ldap = new SimpleLDAP(settings);
    done();
  });

  // destroy any existing ldap connection
  afterEach((done) => {
    ldap.destroy();
    done();
  });

  describe('ldap client', () => {
    it('new creates new instance of client', (done) => {
      expect(ldap.client).to.be.instanceOf(ldapjs.Client);
      done();
    });

    it('is destroyable', () => {
      ldap.destroy();
      expect(ldap.client).to.be.null;
    });

    it('is destroyable after pipe', (done) => {
      ldap.get()
        .pipe(through.obj(function (obj, _, cb) {
          // relabel `idNumber` as `id`, `uid` as`username`,
          // and create a fullName property. Ditch the rest.
          this.push({
            id: obj.idNumber,
            username: obj.uid,
            fullName: `${obj.givenName} ${obj.sn}`,
          });
          cb();
        }))
        .pipe(concat((data) => {
          expect(data).to.eql([{
            id: 1234567,
            username: 'artvandelay',
            fullName: '<NAME>',
          }, {
            id: 765432,
            username: 'ebenes',<commit_msg>test(destroy()): Test destroying client after pipe.<commit_after>/* global describe, it, before, beforeEach, after, afterEach */

import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import through from 'through2';
import concat from 'concat-stream';
import ldapjs from 'ldapjs';
import settings from './settings.example.js';
import TestLDAPServer from './ldapServer';
import mockData from './mockData';
import SimpleLDAP from '../src/';

const { expect } = chai;
chai.use(chaiAsPromised);

describe('LDAP', () => {
  let ldap; // the ldap client
  const server = new TestLDAPServer();

  // start the LDAP server for testing
  before((done) => {
    server
      .start()
      .then(done)
      .catch(done);
  });

  after((done) => {
    server
      .stop()
      .then(done)
      .catch(done);
  });

  // create a new connection to test LDAP server
  beforeEach((done) => {
    ldap = new SimpleLDAP(settings);
    done();
  });

  // destroy any existing ldap connection
  afterEach((done) => {
    ldap.destroy();
    done();
  });

  describe('ldap client', () => {
    it('new creates new instance of client', (done) => {
      expect(ldap.client).to.be.instanceOf(ldapjs.Client);
      done();
    });

    it('is destroyable', () => {
      ldap.destroy();
      expect(ldap.client).to.be.null;
    });

    it('is destroyable after pipe', (done) => {
      ldap.get()
        .pipe(through.obj(function (obj, _, cb) {
          if (!obj) return cb();
          // relabel `idNumber` as `id`, `uid` as`username`,
          // and create a fullName property. Ditch the rest.
          this.push({
            id: obj.idNumber,
            username: obj.uid,
            fullName: `${obj.givenName} ${obj.sn}`,
          });
          return cb();
        }))
        .pipe(concat((data) => {
          expect(data).to.eql([{
            id: 1234567,
            username: 'artvandelay',
            fullName: '<NAME>',
          }, {
            id: 765432,
            username: 'ebenes',
{'fraction_non_alphanumeric': 0.16145307769929365, 'fraction_numerical': 0.007063572149344097, 'mean_word_length': 2.255336617405583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '6156945', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1241, 'n_words': 317}